Monday, August 18, 2008

Sharepoint Document Property Promotion and Demotion

I have been playing around with XML document, its meta data and property promotion/demotion lately. I was able to integrate XML meta data with SharePoint parser to promote/demote meta data automatically in a SharePoint Document Library.

As in, consider a scenario:



I want, when values of M1 and M2 are changed in XML document, metadata in columns (“Metadata 1” and “Metadata 2”) should be automatically updated. If I change value in metadata columns (“Metadata 1” and “Metadata 2”) content in my XML document should be updated accordingly.

I have achieved this functionality using SharePoint’s out-f-box “XML Parser Support”. It will be SharePoint’s responsibility to keep metadata in sink . Take a look at code below:
[code]
site = new SPSite("http://indvtstpcmsp01");
web = site.OpenWeb();
SPList lst = web.Lists["XML Metadata Promotion Demotion"];
foreach (SPField field in lst.Fields)
{
if (field.Title.ToString() == "Myfield")
{
field.XPath = "/*[local-name(.)='root']/*[local-name(.)='firstname']";
field.Update();
lst.Update();
}
}
[/code]

one needs to add PI in XML document as well.
Specify target as: MicrosoftWindowsSharePointServices
Specify value as(based on what content type, does SPField belong to?): ContentTypeID="0x010100BE9DFAFE2B8D034480038C5A149A72F9"

By doing this, we get relief from those event handlers,which one needs to right, to update metadata columns during document(.xml) check-in, in a SharePoint library.

Hope this helps.

Some Info: [Link 1: MSDN - Document Property Promotion Demotion]

Cheers,

1 comment:

Maksym Dykhtiaruk said...

Do you have any idea how to block property demotion, when I download documents from SP?