SharePoint 2013 bulk Item Update C# code

For more information check this link.        
http://sharepointkitchen.blogspot.com.au/2014/12/bulk-insertupdatedelete-items-from.html


public static void BulkUpdate()
        {
            var siteUrl = "http://zdc1ws048:4321/test/Sharepoint2010";
            var listName = "TestList";
            var columnName = "Title";
            var searchValue = "TestValue07";
            var newValue = "It is Updated";

            try
            {
                using (SPSite _oSite = new SPSite(siteUrl))
                {
                    using (SPWeb _oWeb = _oSite.OpenWeb())
                    {
                        SPList _oList = _oWeb.Lists.TryGetList(listName);
                        if (_oList != null)
                        {
                            _oWeb.AllowUnsafeUpdates = true;
                            Guid listGuid = _oList.ID;
                            StringBuilder updateBuilder = new StringBuilder();
                            updateBuilder.Append("");
                            SPQuery query = new SPQuery();
                            query.Query = "" +
                                              "" +
                                                 "" +
                                                 "" + searchValue + "" +
                                              "
" +
                                           "
";

                            SPListItemCollection _oListCollection = _oList.GetItems(query);
                            //Looping through the ListItemCollection and forming the deleteBuilder
                            //here, we are using "Delete" as cmd
                            foreach (SPListItem item in _oListCollection)
                            {
                                updateBuilder.Append("");
                                updateBuilder.Append("" + listGuid + "");
                                updateBuilder.Append("" + Convert.ToString(item.ID) + "");
                                //Column1 is my column Name , which I am updating here.
                                //If we want to update another columns we need to add here.
                                //here urn:schemas-microsoft-com:office:office# is STATIC TEXT
                                updateBuilder.Append("" + newValue + " ");
                                updateBuilder.Append("Save");
                                updateBuilder.Append("
");
                            }
                            updateBuilder.Append("
");
                            _oWeb.ProcessBatchData(updateBuilder.ToString());
                            _oWeb.Update();
                            _oWeb.AllowUnsafeUpdates = false;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }

Comments

Popular posts from this blog

How to get SharePoint dll version using JavaScript quickly

SharePoint App Only Registration Key Renewal script