Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

In the UI I can drill down into a ContentType settings -> Document Information Panel settings -> and set 'Show Always' to true (marking the check box).

How do i set this option through code? (or in a contenttype defition in a feature)

share|improve this question

2 Answers 2

up vote 4 down vote accepted

This information is stored as an XmlDocument in the Content Type. The SPContentType has a property called XmlDocuments which is a collection of XmlDocument objects. You can get the Xml containing the info like this;:

string xml = contentType.XmlDocuments["http://schemas.microsoft.com/office/2006/metadata/customXsn"];

This string contains Xml. For the DIP you should check the /customXsn/openByDefault element. A value of True means that the DIP is shown, empty or False will not show it.

To modify this you have to retrieve the Xml, change the value, remove the current XmlDocument from the content type and add your newly constructed xml and finally update it. Like this:

string schema = "http://schemas.microsoft.com/office/2006/metadata/customXsn";
// load old settings
string xml = contentType.XmlDocuments[schema];
// load it in an Xml Document
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("xsn",schema);
// get the DIP info node
XmlNode node = doc.SelectSingleNode("/xsn:customXsn/xsn:openByDefault", nsmgr);
// Set it to true
node.InnerText = bool.TrueString;
// delete the old one
contentType.XmlDocuments.Delete(schema);
// add the new xml
contentType.XmlDocuments.Add(doc);
// update the CT
contentType.Update();
share|improve this answer
    
Did not know that. Good stuff Wictor. –  Charles Lee Mar 11 '10 at 14:32
    
Yea, isn't SP beautiful - there are so much stuff to learn and find out. That's why I'm still love my work! –  Wictor Wilen MCA MCM MVP Mar 11 '10 at 14:44
    
To 'Love' SP is a little strong... :o) It is more a love-hate relationship. –  trgraglia Aug 6 '12 at 12:29

In the meantime i found the 'feature definition' solution (thanks to SharePoint Manager). Add the following XML to the ContentType definition in the elements file:

<XmlDocuments>
  <XmlDocument NamespaceURI="http://schemas.microsoft.com/office/2006/metadata/customXsn">
    <customXsn xmlns="http://schemas.microsoft.com/office/2006/metadata/customXsn">
      <xsnLocation></xsnLocation>
      <cached>True</cached>
      <openByDefault>True</openByDefault>
      <xsnScope></xsnScope>
    </customXsn>
  </XmlDocument>
</XmlDocuments>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.