Reset Fields

Reset Fields

Reset Fields C# Web Control Code

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

Sitecore.Data.Database db = Sitecore.Configuration.Factory.GetDatabase("master");
Sitecore.Data.Items.Item targetItem = db.GetItem("/sitecore/content/Home/Developers/DataTemplates/StandardValues");
if (targetItem == null) return;

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.Write("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);
string displayName = Sitecore.StringUtil.GetString(item.DisplayName, item.Name);
//using : for colon and   for space
output.Write("{0}: {1}", "Item", displayName);
output.RenderEndTag(); //P

using (new Sitecore.SecurityModel.SecurityDisabler())
{
try
{
Sitecore.Data.Fields.Field field = targetItem.Fields["TeaserAbstract"];
if (targetItem.Fields["TeaserAbstract"] != null)
{
if (field.ContainsStandardValue)
output.Write("{0}&#58;&#160;{1}", field.Name + " field", "<b>Contains Standard Value</b>");
else
{
targetItem.Editing.BeginEdit();
field.Reset();
targetItem.Editing.EndEdit();
output.Write("{0}&#58;&#160;{1}", field.Name + " field", "<b>Set to Standard Value</b>");
}
}
}
finally
{
output.RenderEndTag(); //Div

}
}

Reset Fields C# Web Control Output

Abstract field: Set to Standard Value

Sources