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