Show Word Doc

Show Word Doc

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Context
  • Sitecore.Data.Database
  • Sitecore.Data.Fields.HtmlField
  • Sitecore.Data.Items.Item
  • Sitecore.MainUtil

Show Word Doc C# Web Control Code

 //get Simple Fields metadata item from context database using item guid
Sitecore.Data.Database db = Sitecore.Context.Database;
Sitecore.Data.Items.Item item = db.GetItem("{EC44470F-FF45-4023-95C2-EC886FD33D0C}");
if (item == null) return;

Sitecore.Data.Fields.WordDocumentField wordDocFld = item.Fields["example word document"];
if (wordDocFld == 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);
//using : for colon and   for space
output.Write("{0}: {1}", "Item", item.DisplayName);
output.RenderEndTag(); //P

output.Write("{0}&#58;&#160;{1}", wordDocFld.InnerField.DisplayName + " Field Value", "<p><b>" + wordDocFld.Value + "</b></p>");
output.Write("{0}&#58;&#160;{1}", wordDocFld.InnerField.DisplayName + " HTML Value", "<p><b>" + wordDocFld.Html + "</b></p><br/>");
output.Write("{0}&#58;&#160;{1}", wordDocFld.InnerField.DisplayName + " Plain Text", "<p><b>" + wordDocFld.PlainText + "</b></p>");
output.RenderEndTag(); //Div


Show Word Doc C# Web Control Output


Example Word Document Field Value: 

{8A4E61F1-1120-4B4B-A2DE-17AA6CEF3A0B}00000651

This content

was created

using a

Word Add-on

to Internet

Explorer

 

00000129Example Word Document HTML Value: 

This content

was created

using a

Word Add-on

to Internet

Explorer

 


Example Word Document Plain Text: 

This content was created using a Word Add-on to Internet Explorer