SharePoint Webs web service CreateContentType and UpdateContentType
I was experimenting with the SharePoint Webs web service CreateContentType and UpdateContentType methods recently. The goal was to create a base content type and update it by adding an additional column with a separate web service call. According to the documentation you are suppose to use the <FieldRefs><FieldRef /></FieldRef> Xml structure to create an XmlNode node and pass into to the method. Well, the documentation is wrong. Thank goodness I ran across this post in the forum which pointed me in the right direction.
The proper Xml structure for the fields is shown below:
<Fields>
<Method ID="1">
<Field ID="{246D0907-637C-46b7-9AA0-0BB914DAA832}" Name="_Author" DisplayName="Author" Hidden="FALSE" />
</Method>
<Method ID="1">
<Field ID="{038D1503-4629-40f6-ADAF-B47D1AB2D4FE}" Name="Company" DisplayName="Company" Hidden="FALSE" />
</Method>
<Method ID="1">
<Field ID="{0FC9CACE-C5C2-465d-AE88-B67F2964CA93}" Name="_Category" DisplayName="Category" Hidden="FALSE" />
</Method>
<Method ID="1">
<Field ID="{1DAB9B48-2D1A-47b3-878C-8E84F0D211BA}" Name="_Status" DisplayName="Status" Hidden="FALSE" />
</Method>
<Method ID="1">
<Field ID="{52578FC3-1F01-4f4d-B016-94CCBCF428CF}" Name="_Comments" DisplayName="Comments" Hidden="FALSE" />
</Method>
</Fields>
The method ID attribute is an indicator, apparently, on what to do with the field. ID=1 means add it to the content type, ID=2 means update the field and ID=3 indicates you want the field deleted. This seems a bit odd since you are passing a separate XmlNode for newFields in the CreateContentType() method and in the UpdateContentType method passing newFields, updateFields and deleteFields as separate parameters. Shouldn't that be enough to let the method know what to do with each node?
Hopefully this will save others some time in the future. In the meantime, the documentation needs to be updated properly to reflect the expected structure.
Comments
- Anonymous
November 11, 2008
Thanks a lotThis was a lifesaver - Anonymous
April 25, 2010
Hi Cliff,Could please elabaratre the post,How do you pass paremeters to create contenttype method? - Anonymous
April 25, 2010
Rama,Perhaps this documentation will help. http://msdn.microsoft.com/en-us/library/webs.webs.createcontenttype(v=office.12).aspx. XML structures like the one mentioned above are passed as XmlNode to the web service. You create the XmlNode and then add nodes and attributes to it as needed.