Posted by: R Manimaran | July 30, 2010

SharePoint List Operation using SharePoint Web Services – Part1

I used SharePoint Object model more in the project than Web Services. I planned to do a walk -through how to do the list operation using SharePoint WebSerives.

Here we go.

1. First add reference to the following SharePoint Web Services.

  • Web.asmx
  • Lists.asmx
  • View.asmx

Now the Code.

WebService Initiation:

WebSvrWebs.Webs oWebs = new SPObjecModel.WebSvrWebs.Webs()
WebSvrLists.Lists oLists = new SPObjecModel.WebSvrLists.Lists()
PreAuthenticate = true,
Credentials = CredentialCache.DefaultCredentials

WebSvrViews.Views oViews = new SPObjecModel.WebSvrViews.Views()
PreAuthenticate = true,
Credentials = CredentialCache.DefaultCredentials

Add a new List and add some columns:

XmlNode xnNewLists = oLists.AddList(listName, description, 100);
XmlDocument xmlDoc = new XmlDocument();
XmlNode xnNewFields = xmlDoc.CreateNode(XmlNodeType.Element, “Fields”, “”);

xnNewFields.InnerXml +=
“<Method ID=’1′>” +
“<Field Type=’Text’ Title=’EmpName’ DisplayName = ‘Employee Name’ Required=’TRUE’ Description = ‘Enter the Name’/>” +
xnNewFields.InnerXml +=
“<Method ID=’2′>” +
“<Field Type=’Text’ DisplayName=’Designation’/>” +
xnNewFields.InnerXml +=
<Method ID=’3′>” +
“<Field Type=’Number’ DisplayName=’Years of Exp’/>” +

Set QuickLaunch Property to true:

XmlNode xnProperties = xmlDoc.CreateNode(XmlNodeType.Element, “List”, “”);
XmlAttribute xnQuickLaunchAttribute = (XmlAttribute)xmlDoc.CreateNode(XmlNodeType.Attribute, “OnQuickLaunch“, “”);
xnQuickLaunchAttribute.Value = “True“;
Enable Versioning:

XmlAttribute xnEnableversioningAttribute = (XmlAttribute)xmlDoc.CreateNode(XmlNodeType.Attribute, “EnableVersioning“, “”);
xnEnableversioningAttribute.Value = “True“;

XmlNode updateList = oLists.UpdateList(listName, xnProperties, xnNewFields, null, null, null);

Above code will create a new list and add some columns.
It also Enable the Versioning in the new list.
By default OnQuichLaunch property is set to false, so it won’t come in Quick view. There is no documentation for how to use in property in Microsoft SDK. Here I set the OnQuickLaunch property value to true, so that it will come in the Quick launch on List Creation.

In the part 2 I have explained how to add the newly added columns to default view, add a list item and update a List item.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: