Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am looking for adding SPListItem using SPWeb.ProcessBatchData method. Could any one please help me on syntax for adding list item to my custom list.

share|improve this question
add comment

1 Answer

if you want to use SPWeb.ProcessBatchData method then follow this tutorial,

Inserting New Items to List using ProcessBatchData

why you must have to use "ProcessBatchData" when you can easily get SPWeb.GetList(siteURL) method to get list and add items to it.

using System;
using Microsoft.SharePoint;

namespace Test
{
   class ConsoleApp
   {
      static void Main(string[] args)
      {
         using (SPSite site = new SPSite("http://localhost/sites/sitecollection"))
         {
            using (SPWeb web = site.OpenWeb("sitecollection/subsite"))
            {
               string listUrl = "/sites/sitecollection/subsite/Lists/Announcements";
               SPList list = web.GetList(listUrl);
               Console.WriteLine("List URL: {0}", list.RootFolder.ServerRelativeUrl);
               SPListItem oSPListItem = list.Items.Add();
               oSPListItem["Title"] = "Hello SharePoint";
               oSPListItem.Update();
            }
         }
         Console.ReadLine();
      }
   }
}

taken from MSDN GetList method

For More examples check this out

programmatically-add-items-list

share|improve this answer
    
First of thanks for taking time to answer. No doubt I can use the other approach. But in my case I am adding multiple list items inside a loop. And item.Update() inside the loop is violation of SharePoint coding rules. –  V.B Sep 5 '12 at 7:48
    
I tried that before and it worked for me, however I put a link up there where he is inserting multiple items using process batch method :) –  SharePointer Sep 5 '12 at 8:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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