Share via


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 = "https://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

----------------

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

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

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

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

Keep Coding.... :)

Comments

  • Anonymous
    March 18, 2007
    how can I save data into sharepoint list if the field type or column type of is usermulti or a multivalued.

  • Anonymous
    May 22, 2007
    SharePoint&#39;s Webs webservice can be used to add/delete/update site columns. Unfortunatley MSDN/SDK

  • Anonymous
    October 31, 2007
    Interesting... I'd like to delete some bogus/duplicate  columns left by InfoPath publish failures, so this may do the trick.

  • Anonymous
    May 18, 2008
    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 !

  • Anonymous
    October 31, 2010
    Does this actually work??? anyone? I also followed example and it did not work.

  • Anonymous
    May 24, 2011
    This does not look as a correct service call according the the MS' schema.

  • Anonymous
    July 04, 2012
    Very useful informationyou can search information about Theme for sharepoint 2010 at sharepoint2010template.com