Tuesday, January 19, 2010

How to update ShowInFileDlg programmatically

At some point in your SharePoint development life time you will probably need to update the ShowInFileDlg attribute of a Site Column.

If you will try to do that by a feature and update the XML with new Field's attributes values, the changes will only take effect on new instances, and will not effect on exsisting ContentTypes or Lists that use these Site Columns.

Programmatically updating the Site Column and the Content Type, the changes will be deployed to the children as well.

Here is a generic method for updating any attribute of the Field element and forcing the changes to the Content Type and its children:

public void UpdateFieldAttribute(string siteCollectionURL, string siteColumnName, string contentTypeName, string fieldAttributeName, string fieldAttributeValue)
SPSite site = null;
SPWeb web = null;
using (site = new SPSite(siteCollectionURL))
using (web = site.OpenWeb())

SPField siteColumn = site.RootWeb.Fields.GetField(siteColumnName);
XmlDocument fieldSchemaXml = new XmlDocument();
XmlNode fieldXmlNode = fieldSchemaXml.SelectSingleNode("Field");
XmlAttribute attr = fieldXmlNode.Attributes[fieldAttributeName];
attr.InnerText = fieldAttributeValue; ;

siteColumn.SchemaXml = fieldXmlNode.OuterXml;

SPContentType contentType = site.RootWeb.ContentTypes[contentTypeName];

contentType.Update(true, false); //Updating the content type is important or the changes will not be reflected
if (web != null)
if (site != null)


Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...

The information here is great. I will invite my friends here.


Anonymous said...


Anonymous said...

Genial post and this fill someone in on helped me alot in my college assignement. Thank you on your information.

Anonymous said...

nice one! but why did you create the instance of spweb? it´s never used.

Anonymous said...

jtnkilp, xrumer linklist , eIDrfiS.

神待ち said...


出合い系 said...


ワンピース said...


何婉羽 said...

Google's vision of a pc in which all the things was on the net turned heads while in the tech world past yr, should the first Chromebooks appeared. The real acer aspire 5536 battery
COMPAQ CQ61 Laptop Batteries earth? Considerably less impressed. Apple's iPad proved a much more persuasive concept for people today spending their hard-earned monies, but Google, undeterred, has gone back again towards the drawing board and up to date its Chrome OS.

Martin said...

Setting ShowInFileDlg doesn't work for Managed Metadata columns. You must customize Document Information Panel. More information can be found here http://social.technet.microsoft.com/Forums/en-US/17e1f67a-cf24-4abe-9366-2fba8e1d8fe4/hide-managed-metadata-column-in-document-information-pannel