.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Articles >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Articles

How to add new list item in sharepoint using Lists.asmx web service

Posted By:Sunil Yadav       Posted Date: May 24, 2010    Points: 15    Category: SharePoint    URL: http://www.dotnetspark.com  

This article explains how we can add sharepoint list item using list.asmx webservice

The UpdateListItems  method of the Lists Web service can be use to update items through web service.

Following are the steps to accomplish above :
1.Add a web service reference to your application.

    1.Right click on the application or reference folder
    2.Select "Add Web reference" and provide "http://mossserver/_vti_bin/lists.asmx" url.

2.Use System.Xml.XmlElement object to create Batch element in CAML format.

3.Determine the Cmd attribute which determines the operations to be performed which are as follows:

    1. New
    2. Delete
    3. Update

Here is the sample code:

TimeSpan ts = new TimeSpan(0, 0, 062094);
    TimeSpan ts1 = new TimeSpan(0, 0, 062102);

    localhost.Lists ls = new localhost.Lists();
    ls.Credentials = new System.Net.NetworkCredential("sunil", "passsword");
    ls.Url = "http://mossserver/_vti_bin/lists.asmx";
    XmlNode node = ls.GetListAndView("My Attendence", "");
    string sListID = node.ChildNodes[0].Attributes["Name"].Value;
    string sViewID = node.ChildNodes[1].Attributes["Name"].Value;

    XmlDocument doc = new XmlDocument();
    XmlElement batch = doc.CreateElement("Batch");

    batch.SetAttribute("OnError", "Continue");
    batch.SetAttribute("ListVersion", "1?);
    batch.SetAttribute("ViewName", sViewID);

    batch.InnerXml = "< Method ID='1' Cmd='New'>" +
    "New" +
    "Time" +
    "" + ts.ToString() + "" +
    "" + ts1.ToString() + "" +
    ls.UpdateListItems(sListID, batch);

also update and delete operation can be performed as:


batch.InnerXml = "" +
    "2" +
    "" + tspan.ToString() + "" +


  batch.InnerXml = "" +
    "3" +

Where 3" is the ID of the Item in the list which needs to be specify tp perform Update and Delete operation.



 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend