Tags

, , , , ,

void UpdateList()
        {
            StringBuilder methodBuilder = new StringBuilder();
            string batch = string.Empty;
            string newValue="mmmm";
            string updateColumn = "SampleColumn";
 
 
            try
            {
                string batchFormat =    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                                        "<ows:Batch OnError=\"Continue\">{0}</ows:Batch>";
                string methodFormat = "<Method ID='{0}' >" +
                                        "<SetList>{1}</SetList>" +
                                        "<SetVar Name='Cmd'>Save</SetVar>" +
                                        "<SetVar Name='ID'>{2}</SetVar>" +
                                        "<SetVar Name='urn:schemas-microsoft-com:office:office#{3}'>{4}</SetVar>" +
                                        "</Method>";
               
                using (SPSite siteCol = new SPSite("SampleSite"))
                {
                    using (SPWeb web = siteCol.OpenWeb())
                    {
 
                        // Get the list containing the items to update
                        SPList list = web.Lists["SampleList"];
                        string listGuid = list.ID.ToString();
                        SPListItemCollection allItems = list.GetItems();
 
                        // Build the CAML update commands.
                        for (int i = 0; i < allItems.Count; i++)
                        {
                            int itemID = allItems[i].ID;
                            methodBuilder.AppendFormat(methodFormat, itemID, listGuid, itemID, updatedColumn, newValue);
                        }
                        web.AllowUnsafeUpdates = true;
 
                        // Generate the CAML
                        batch = string.Format(batchFormat, methodBuilder.ToString());
 
                        // Process the batch
                        string batchReturn = web.ProcessBatchData(batch);
                      
                    }
                    //done
                }
 
            }
            catch (Exception ex)
            {
        //show the error
            }
 
        }
}
 
Advertisements