문제

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)

도움이 되었습니까?

해결책

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();

다른 팁

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>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top