Posted by: R Manimaran | November 9, 2010

SharePoint: Setting ShowInFileDlg using Object Model.

In the Previous post I wrote how to set the value for ShowInFileDlg attribute in Fields.xml which will show/hide the field in Word Document Information panel.

Suppose you have added the Site Columns using SharePoint Object model like this.

SPFieldText Fieldtxt = (SPFieldText) Fields.Add(“Keyword”,SPFieldType.Text,false);

You may thing that there will be a properties like ShowInFileDlg. But in object model it is missing.

Then how to set it.

We need to modify the Schema.xml file of the Site Column. I wrote a Small helper function which will set the value for the ShowFileDlg attribute.

public static void ShowHideFieldinFileDlg(string siteUrl,string strFieldName,bool valuestring)


using (SPSite site = new SPSite(siteUrl))


using (SPWeb web = site.OpenWeb())


//Get the Field from the Site Columns

SPField siteColumn = site.RootWeb.Fields.GetField(strFieldName);

XmlDocument fieldSchemaxml = new XmlDocument();


//Create a New Attribute for ShowInFileDlg

XmlAttribute newAttribute = fieldSchemaxml.CreateAttribute(“ShowInFileDlg”);

newAttribute.Value = valuestring.ToString().ToUpper();

XmlNode fldXmlNode = fieldSchemaxml.SelectSingleNode(“Field”);

//get the attribute collection

XmlAttributeCollection attr = fldXmlNode.Attributes;


siteColumn.SchemaXml = fldXmlNode.OuterXml;







  1. I tried that, I got an error “value does not fall in the expected range”. Any idea?

    • Hi, in which line you got the error? is it possible to post your code here?

  2. Could I hide the fields per item (dynamically)?

    • For Item level you can’t hide it using OOTB. In that case you need to write JQuery or Javascript in NewForm.aspx or you need to create the custom form for getting the input.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: