Monday, November 15, 2010

Update List Column Programmatically for SharePoint 2007

Two ways of doing this:

First one is via SharePoint object model:


SPList oList = oWeb.Lists["Technical"];
SPField myField = oList.Fields["Sub-tag"];
String schema = " xx ";
myField.SchemaXml = schema;
myField.Update();


the Second way is via Lists.asmx web service:

XmlNode listNode = mylistsrv.GetList("Technical");
string version = listNode.Attributes["Version"].Value;
string guid = listNode.Attributes["Name"].Value;

XmlDocument xmlDoc = new XmlDocument();
XmlElement updateFields = xmlDoc.CreateElement("Fields");

string fieldXml = "";

updateFields.InnerXml = fieldXml;
XmlNode result = mylistsrv.UpdateList(guid, null, null, updateFields, null, version);