Word Doc Properties

Word Doc Properties

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

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

Word Document Fields

  • Stored as BLOBs in the Sitecore databases
  • There is no web control in declarative markup
  • Field values can be displayed by the FieldRenderer.Render() method and FieldRenderer control
  • Does not natively support displaying field values in the Page Editor

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 wdFld = item.Fields["example word document"];
if (wdFld == 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}", "Field", wdFld.InnerField.DisplayName);
output.RenderEndTag(); //P

output.Write("Can Read? " + "<b>" + wdFld.InnerField.CanRead.ToString() + "</b><br/>"); 
output.Write("Can Write? " + "<b>" + wdFld.InnerField.CanWrite.ToString() + "</b><br/>"); 
output.Write("Contains Standard Value? " + "<b>" + wdFld.InnerField.ContainsStandardValue.ToString() + "</b><br/>"); 
output.Write("Definition: " + "<b>" + wdFld.InnerField.Definition.Name + "</b><br/>"); 
output.Write("Description: " + "<b>" + wdFld.InnerField.Description + "</b><br/>"); 
output.Write("Display Name: " + "<b>" + wdFld.InnerField.DisplayName + "</b><br/>"); 
output.Write("Has Blob Stream? " + "<b>" + wdFld.InnerField.HasBlobStream.ToString() + "</b><br/>"); 
output.Write("Has Value? " + "<b>" + wdFld.InnerField.HasValue.ToString() + "</b><br/>"); 
output.Write("ID: " + "<b>" + wdFld.InnerField.ID.ToString() + "</b><br/>"); 
output.Write("Contains Inherited Value? " + "<b>" + wdFld.InnerField.InheritedValue + "</b><br/>"); 
output.Write("Is Blob Field? " + "<b>" + wdFld.InnerField.IsBlobField.ToString() + "</b><br/>"); 
output.Write("Has Been Modified? " + "<b>" + wdFld.InnerField.IsModified.ToString() + "</b><br/>"); 
output.Write("Key: " + "<b>" + wdFld.InnerField.Key + "</b><br/>"); 
output.Write("Language: " + "<b>" + wdFld.InnerField.Language.Name + "</b><br/>"); 
output.Write("Name: " + "<b>" + wdFld.InnerField.Name + "</b><br/>"); 
output.Write("Reset Blank On? " + "<b>" + wdFld.InnerField.ResetBlank.ToString() + "</b><br/>"); 
output.Write("Section Name: " + "<b>" + wdFld.InnerField.Section + "</b><br/>"); 
output.Write("Sort Order: " + "<b>" + wdFld.InnerField.Sortorder.ToString() + "</b><br/>"); 
output.Write("Shared? " + "<b>" + wdFld.InnerField.Shared.ToString() + "</b><br/>"); 
output.Write("Source: " + "<b>" + wdFld.InnerField.Source + "</b><br/>"); 
output.Write("Title: " + "<b>" + wdFld.InnerField.Title + "</b><br/>"); 
output.Write("Tooltip: " + "<b>" + wdFld.InnerField.ToolTip + "</b><br/>"); 
output.Write("Translatable? " + "<b>" + wdFld.InnerField.Translatable.ToString() + "</b><br/>"); 
output.Write("Type: " + "<b>" + wdFld.InnerField.Type + "</b><br/>"); 
output.Write("Type Key: " + "<b>" + wdFld.InnerField.TypeKey + "</b><br/>"); 
output.Write("Unversioned? " + "<b>" + wdFld.InnerField.Unversioned.ToString() + "</b><br/>"); 
output.Write("Validation Regex: " + "<b>" + wdFld.InnerField.Validation + "</b><br/>"); 
output.Write("Validation Message: " + "<b>" + wdFld.InnerField.ValidationText + "</b><br/>"); 
output.Write("Value: " + "<b>" + wdFld.InnerField.Value + "</b>");

output.RenderEndTag(); //Div


C# Web Control Real-time Output

Field: Example Word Document

Can Read? True
Can Write? True
Contains Standard Value? False
Definition: Example Word Document
Description: 
Display Name: Example Word Document
Has Blob Stream? False
Has Value? True
ID: {652F265E-C639-4FAD-ABC7-BD6751298C4A}
Contains Inherited Value? {8A4E61F1-1120-4B4B-A2DE-17AA6CEF3A0B}00000651

This content

was created

using a

Word Add-on

to Internet

Explorer

 

00000129 

Is Blob Field? True
Has Been Modified? False
Key: example word document
Language: en
Name: Example Word Document
Reset Blank On? False
Section Name: Simple Field Types
Sort Order: 1200
Shared? False
Source: 
Title: 
Tooltip: 
Translatable? False
Type: Word Document
Type Key: word document
Unversioned? False
Validation Regex: 
Validation Message: 
Value: {8A4E61F1-1120-4B4B-A2DE-17AA6CEF3A0B}00000651

This content

was created

using a

Word Add-on

to Internet

Explorer

 

00000129