Cliff Green's Blog

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.

Published Friday, May 30, 2008 7:44 PM by green.cliff
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Sudip said:

Thanks a lot

This was a lifesaver

November 12, 2008 5:10 AM

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required
Submit

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker