I was working on a project and I had custom content types defined in a feature. These content types had document templates, and I wanted to control the Document Information Panel (DIP) when a document is opened in Word.
The following code snippet takes an SPContentType object and adds a custom XSN element to the content types XmlDocuments collection. Setting the openByDefault value to “True” will force the DIP to open when the document loads. I use a FeatureReceiver to run this code against a newly provisioned Content Type.
public static void ConfigureContentTypes(SPContentType ct)
{
XmlDocument doc = GetCustomXsnDocument();
ct.XmlDocuments.Add(doc);
ct.Update(true);
}
private static XmlDocument GetCustomXsnDocument()
{
XmlDocument doc = new XmlDocument();
string xml = "<customXsn xmlns=\"http://schemas.microsoft.com/office/2006/metadata/customXsn\"><xsnLocation></xsnLocation><cached>True</cached><openByDefault>True</openByDefault><xsnScope></xsnScope></customXsn>";
doc.LoadXml(xml);
return doc;
}
You can find information about the child CustomXsn elements on this MSDN link: Content Type Document Information Panel Schema
Hope this helps.
Работя по един проект, в който имам дефинирани Content Types в Feature. Тези Content Types имат различни document templates, и ми се наложи да конфигурирам Document Information Panel (DIP) да се отваря автоматично. Това става лесно чрез интерфейса, но трябваше да е част от автоматизиран деплоймент.
В следващия код показвам как става това. Подаваме SPContentType обект, на който му се дефинира нов CustomXsn елемент в своята XmlDocuments колекция. Ако под-елемента openByDefault е “True”, DIP ще се покаже при отварянето на документа. Използвам FeatureReceiver за прекарам мойте Content Types през този статичен метод:
public static void ConfigureContentTypes(SPContentType ct)
{
XmlDocument doc = GetCustomXsnDocument();
ct.XmlDocuments.Add(doc);
ct.Update(true);
}
private static XmlDocument GetCustomXsnDocument()
{
XmlDocument doc = new XmlDocument();
string xml = "<customXsn xmlns=\"http://schemas.microsoft.com/office/2006/metadata/customXsn\"><xsnLocation></xsnLocation><cached>True</cached><openByDefault>True</openByDefault><xsnScope></xsnScope></customXsn>";
doc.LoadXml(xml);
return doc;
}
Можете да намерите повече информация за CustomXsn елемента на този MSDN линк: Content Type Document Information Panel Schema
Дано това помогне на някой.