Item Archives

Item Archives

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • System.Collections.Generic.List<string>
  • Sitecore.Configuration.Factory
  • Sitecore.Data.Database
  • Sitecore.Data.Items.Item
  • System.Text.StringBuilder

Item Archives C# Web Control Code

Sitecore.Data.Items.Item item = this.GetItem();
if (item == null) return;

Sitecore.Data.Database db = Sitecore.Configuration.Factory.GetDatabase("master");
System.Text.StringBuilder builder = new System.Text.StringBuilder();

Sitecore.Data.Archiving.DataArchives archives = db.Archives;
if (archives == null) return;

System.Collections.Generic.List<string> archiveNames = db.ArchiveNames;
if (archiveNames == null) return;

//using &#58; for colon and &#160; for space
builder.Append("Archives Count&#58;&#160;<b>" + archives.Count.ToString() + "</b><br/>");
builder.Append("Archive Capacity&#58;&#160;<b>" + archiveNames.Capacity.ToString() + "</b><br/>");

string[] names = new string[archives.Count];
int i = 0;
foreach (var archive in archiveNames)
{
    names[i] = archive;
    builder.Append("Name&#58;&#160;<b>" + archives[names[i]].Name + "</b>&#160;&#160;Entry Count&#58;&#160;<b>" + archives[names[i]].GetEntryCount() + "</b><br/>");
    i++;
}

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.Write("{0}", "C# Web Control Real-time Output");
output.RenderEndTag();

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-size:x-small; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P);
output.Write("{0}&#58;&#160;{1}", "Item", item.DisplayName);
output.RenderEndTag(); //P

output.Write("{0}", builder.ToString());

output.RenderEndTag(); //Div

Item Archives C# Web Control Output

Archives Count: 2
Archive Capacity: 4
Name: archive  Entry Count: 0
Name: recyclebin  Entry Count: 60

Notes

  • The two item archives are the archive and the recycle bin