MOSS 2007: WSS 3.0: How to add/delete/update site columns by using SharePoint WebService


SharePoint’s Webs webservice can be used to add/delete/update site columns. Unfortunatley MSDN/SDK doesnot has the sample yet. Here I provide the sample code.


            //webs webservice object


            localhost.Webs websService = new ContentTypeAndSiteColumn.localhost.Webs();


            //url for the webservice


            websService.Url = http://localhost:4040/_vti_bin/Webs.asmx;


            //credential


            websService.Credentials = System.Net.CredentialCache.DefaultCredentials;


 


            //xmldocument object


            XmlDocument xDoc = new XmlDocument();


            //Fields to be added


            XmlElement newFields = xDoc.CreateElement(“Fields”);


            //Fields to be edited


            XmlElement updateFields = xDoc.CreateElement(“Fields”);


            //Fields to be deleted


            XmlElement deleteFields = xDoc.CreateElement(“Fields”);


 


            newFields.InnerXml = “<Method ID=’1′><Field Name=’FieldName’ DisplayName=’FieldDisplayName’ Group=’Group Name’ Type=’Text’/></Method>”;


            newFields.InnerXml = “<Method ID=’2′><Field Name=’FieldName’ DisplayName=’FieldDisplayName’ Group=’Group Name’ Type=’Text’/></Method>”;


            deleteFields.InnerXml = “<Method ID=’3′><Field Name=’FieldName’/></Method>”;


 


            XmlNode returnValue = websService.UpdateColumns(newFields, updateFields, deleteFields);


            MessageBox.Show(returnValue.OuterXml);


 


Related Links


—————-


http://msdn2.microsoft.com/en-us/library/webs.webs.updatecolumns.aspx


http://msdn2.microsoft.com/en-us/library/ms451470.aspx


http://msdn2.microsoft.com/en-us/library/ms437580.aspx


http://msdn2.microsoft.com/en-us/library/webs.webs.getcolumns.aspx


Keep Coding…. 🙂

Comments (7)

  1. mcvilbar says:

    how can I save data into sharepoint list if the field type or column type of is usermulti or a multivalued.

  2. SharePoint&#39;s Webs webservice can be used to add/delete/update site columns. Unfortunatley MSDN/SDK

  3. BobChauvin says:

    Interesting… I’d like to delete some bogus/duplicate  columns left by InfoPath publish failures, so this may do the trick.

  4. ONO says:

    I’m trying to add a new column to a site by using Webs.UpdateColumns method on the Webs web service (just like your example). I’m sending the following node as newFields:

    <Fields>

    <Method ID="1">

     <Field Group="WSS Demo" Type="Text" Name="Test001" DisplayName="Test001" Required="false" />

    </Method>

    </Fields>

    The server throws a exception, with the following details (actually detail – it’s all it contains):

    <detail>

    <errorstring xmlns="http://schemas.microsoft.com/sharepoint/soap/">Value does not fall within the expected range.</errorstring>

    </detail>

    I’ve been tackling this for two days – any help is appreciated.

    Thank you !

  5. Mark says:

    Does this actually work??? anyone? I also followed example and it did not work.

  6. Vukota says:

    This does not look as a correct service call according the the MS' schema.

  7. Very useful informationyou can search information about Theme for sharepoint 2010 at sharepoint2010template.com

Skip to main content