强制文档信息面板显示使用代码或特色式定义
-
16-10-2019 - |
题
在UI中,我可以向下钻入ContentType设置 - >文档信息面板设置 - >并将“显示”始终设置为true(标记复选框)。
如何通过代码设置此选项? (或功能中的ContentType叛逃中)
解决方案
此信息存储为 XmlDocument
在内容类型中。这 SPContentType
有一个称为的属性 XmlDocuments
这是一个集合 XmlDocument
对象。您可以获取包含这样的信息的XML;:
string xml = contentType.XmlDocuments["http://schemas.microsoft.com/office/2006/metadata/customXsn"];
该字符串包含XML。对于蘸酱,您应该检查 /customXsn/openByDefault
元素。一个值 True
意味着显示倾角,空或 False
不会显示。
要修改此内容,您必须检索XML,更改值,从内容类型中删除当前的XMLDOCUMENT,然后添加您新构建的XML并最终对其进行更新。像这样:
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();
其他提示
同时,我找到了“功能定义”解决方案(感谢SharePoint Manager)。将以下XML添加到“元素”文件中的ContentType定义:
<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>