I want to add new item to SharePoint list using web service. I use SharePoint 2013. I found on the net follow code, but I don't understand how to use?

<Batch OnError="Continue">
<Method ID="1" Cmd="New">
    <Field Name="Title">Abcdef</Field>
    <Field Name="Project_x0020_code">999050</Field>
    <Field Name="Status">Open</Field>    

Where I write this code, where I publish? Is there any other way?

Source of the code: SharePoint - How do insert new items using the list web service?


Try using below code by passing ViewName,

<Batch OnError="Continue" ViewName="{D0E978D3-4D39-4CBE-ACEC-BCFB22344252}">
    <Method ID='1' Cmd='New'>
        <Field Name='Title'>The New Task Title</Field>

In another way we can create Web Site Project in Visual studio to illustrate. For that click on Add Web Reference and give the URL to the Web Service,

Its Demonstrated here,



  • "Where I write this code, where I publish? Is there any other way?" is the question here – Robert Lindgren Nov 9 '15 at 8:23
  • Yes, where I write this code, where I running this code? In a VS SharePoint Project, or xml file? I don't know this – zengel Nov 9 '15 at 8:27
  • Yes yes I got to know about your question, here is the link that provides information about it hope this helps, "c-sharpcorner.com/Blogs/7655/…" – Niranjan Kulkarni Nov 9 '15 at 8:34

The XML in your question is passed as an argument to the UpdateListItems method. Below is an item update example from msdn: You will need to use this code in a method in your Visual studio project that will add a new list item. Update the strBatch string to your requirements.

I would suggest to look at new ways of working with SharePoint Lists using the following references: Using CSOM and Using REST

Web_Reference_Folder.Lists listService = new Web_Reference_Folder.Lists();
listService.Credentials= System.Net.CredentialCache.DefaultCredentials;

string strBatch = "<Method ID='1' Cmd='Update'>" + 
    "<Field Name='ID'>4</Field>" +
    "<Field Name='Field_Number'>999</Field></Method>" +
    "<Method ID='2' Cmd='Update'><Field Name='ID' >6</Field>" +
    "<Field Name='Field_DateTime'>

XmlDocument xmlDoc = new System.Xml.XmlDocument();

System.Xml.XmlElement elBatch = xmlDoc.CreateElement("Batch");


elBatch.InnerXml = strBatch;

XmlNode ndReturn = listService.UpdateListItems("List_Name", elBatch);


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.