I have posted before about a method of editing the SharePoint Document properties on a Word document in Office 2010 (and Office 2007). I just found something that completely blew my mind. I spent hours and hours battling with CustomXMLParts, Protected and Readonly documents, and a Save-As dialog… and found out that all that effort was pretty much wasted.
ContentTypeProperties is a collection of MetaProperty objects representing (possibly among other things) the SharePoint properties displayed in the server document properties panel. And you can edit them.
So instead of a mess of XML xpath, namespaces, exception handling and “_x0020_”‘s , if you want to edit a sharepoint list column called “Task Id”, you would do the following:
doc.ContentTypeProperties["Task Id"].Value = "task1";
(Yes, you still might need some exception handling…)
The CustomXMLParts will be updated appropriately, and when you save it to sharepoint, the properties will be populated.
Have a look at the members of the MetaProperty object:
.Name = sharepoint internal column name: “Task Id”
.Id = escaped column name: “Task_x0020_Id”
The other properties are what you would expect.
Please note that this will only work if the word document has been “touched” by SharePoint. See my next post for a quick (and undocumented) method of getting those properties attached in Word 2010.
I’m using this but for me in Office 2010 and SharePoint 2010 (works for Office & SP 2007) the ContentTypeProperties is always null when creating a new doc through the SP doc library interface. Any thoughts on why?