Welcome to MSDN Blogs Sign in | Join | Help

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.... :)

Published Tuesday, January 02, 2007 5:34 PM by Karthikeyan
Filed under:

Comments

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

Monday, March 19, 2007 5:48 AM by mcvilbar

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

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

Tuesday, May 22, 2007 11:54 PM by Aggregated Blogs

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

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

Wednesday, October 31, 2007 1:10 PM by BobC

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

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

Sunday, May 18, 2008 8:37 AM by ONO

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 comments are disabled
 
Page view tracker