{"id":6144,"date":"2020-06-10T13:58:13","date_gmt":"2020-06-10T13:58:13","guid":{"rendered":"https:\/\/www.softreetechnology.com\/?p=6144"},"modified":"2020-06-10T13:58:13","modified_gmt":"2020-06-10T13:58:13","slug":"create-sharepoint-list-items-in-batch-using-csom","status":"publish","type":"post","link":"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-sharepoint-list-items-in-batch-using-csom\/","title":{"rendered":"Create SharePoint list items in batch using CSOM"},"content":{"rendered":"\n<p>           Here, we are going to perform the most useful operation which can be performed in SharePoint platform to make our commercial life easier. We will learn how to create and update list items in batch using CSOM. Using this we can update a huge number of list items in a list. Please follow the below steps to understand the code better.<\/p>\n\n\n\n<p><strong>Step 1: &#8211;<\/strong>  Set the credential by giving input of user ID and Password for SharePoint.<\/p>\n\n\n\n<p><strong>Step 2:&nbsp;&#8211;<\/strong>  Using client context get the web &amp; a list in which we want to update the list items.<\/p>\n\n\n\n<p><strong>Step 3:&nbsp;&#8211;<\/strong>  Using the schema AddFieldAsXML, we can add our custom field as per our requirement. (Here I have created a text field).<\/p>\n\n\n\n<p><strong>Step 4:&nbsp;&#8211;<\/strong>  Now in this step we will create 20 List items in each field present in the list &amp; update the items using the for loop. We are using for loop foe the batch update, only we have to change the condition value of \u2018 i \u2019(e.g.&nbsp; here we used i&lt;20).<\/p>\n\n\n\n<p><strong>Now, check the complete code below.<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;\nusing System.Security;\nusing Microsoft.SharePoint.Client;\n\nnamespace ConsoleApp7\n{\n    class Program\n    {\n        \/\/\/ &lt;summary>\n        \/\/\/ This is the main entry function\n        \/\/\/ &lt;\/summary>\n        \/\/\/ &lt;param name=\"args\">&lt;\/param>\n        static void Main(string [] args)\n        {\n            #region [Variables]\n            string schemaTextField = string.Empty;\n            string password = string.Empty;\n            #endregion #region [SP Variables]\n            ClientContext ctx = null;\n            Web spWeb = null;\n            List spList = null;\n            SecureString securStr = null;\n            ListItemCreationInformation spItemInfo = null;\n            ListItem spItem = null;\n            Field simpleTextField=null;\n            #endregion\n\n            using (ctx = new ClientContext(\"https:\/\/contoso.sharepoint.com\/sites\/sitename\"))\n            {\n              try\n              {\n                securStr = new SecureString();\n                password = \"Enter the password\";\n                foreach (char ch in password)\n                {\n                    securStr.AppendChar(ch);\n                }\n                ctx.Credentials = new SharePointOnlineCredentials(\"Enter UserName\", securStr);\n                spWeb = ctx.Web;\n                ctx.Load(spWeb);\n                spList = spWeb.Lists.GetByTitle(\"listName\");\n                schemaTextField = \"&lt;Field Type='Text' Name='MyCustomTextField' StaticName='MyCustomTextField' DisplayName='MyCustomTextField' \/>\";\n                simpleTextField = spList.Fields.AddFieldAsXml(schemaTextField, true, AddFieldOptions.AddFieldInternalNameHint);\n                ctx.ExecuteQuery();\n                for (var i = 1; i &lt; 20; i++)\n                {\n                    try\n                    {\n                        spItemInfo = new ListItemCreationInformation();\n                        spItem = spList.AddItem(spItemInfo);\n                        spItem[\"Title\"] = \"MyNewItem-\" + i.ToString();\n                        spItem[\"MyCustomTextField\"] = \"My Custom Values-\" + i.ToString();\n                        spItem.Update();\n                    }\n                    catch (Exception ex)\n                    Console.WriteLine(\"Error:- \" + ex.ToString());\n                    }\n                }\n                ctx.ExecuteQuery();\n            }\n            catch (Exception ex)\n            {\n                Console.WriteLine(\"Error:- \" + ex.ToString());\n            }\n           }\n       }\n    }\n} <\/code><\/pre>\n\n\n\n<p>After running the code, we can go to our\nrespective List and check for the items which are now created successfully. <\/p>\n\n\n\n<p>For\noutput please refer below image:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2020\/06\/4.png\" alt=\"\" class=\"wp-image-6145\" width=\"310\" height=\"258\"\/><\/figure>\n\n\n\n<p><strong><em><span style=\"text-decoration: underline;\">Keywords:<\/span><\/em><\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Create\nSharePoint list items in batch using CSOM <\/li><li>Creating\nList item in batch using CSOM <\/li><li>How\nto create bulk list Item using CSOM<\/li><li>Batch\nUpdate in CSOM<\/li><li>Bulk\nUpdate using CSOM<\/li><li>Bulk\nupdate in SharePoint<\/li><li>Batch\nUpdate in SharePoint<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Here, we are going to perform the most useful operation which can be performed in SharePoint platform to make our commercial life easier. We will learn how to create and update list items in batch using CSOM. Using this we can update a huge number of list items in a list. Please follow the below steps to understand the code [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[],"class_list":["post-6144","post","type-post","status-publish","format-standard","hentry","category-sharepoint"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Create SharePoint list items in batch using CSOM - Softree Technology<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-sharepoint-list-items-in-batch-using-csom\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Create SharePoint list items in batch using CSOM - Softree Technology\" \/>\n<meta property=\"og:description\" content=\"Here, we are going to perform the most useful operation which can be performed in SharePoint platform to make our commercial life easier. We will learn how to create and update list items in batch using CSOM. Using this we can update a huge number of list items in a list. Please follow the below steps to understand the code [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-sharepoint-list-items-in-batch-using-csom\/\" \/>\n<meta property=\"og:site_name\" content=\"Softree Technology\" \/>\n<meta property=\"article:published_time\" content=\"2020-06-10T13:58:13+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Create SharePoint list items in batch using CSOM - Softree Technology","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-sharepoint-list-items-in-batch-using-csom\/","og_locale":"en_US","og_type":"article","og_title":"Create SharePoint list items in batch using CSOM - Softree Technology","og_description":"Here, we are going to perform the most useful operation which can be performed in SharePoint platform to make our commercial life easier. We will learn how to create and update list items in batch using CSOM. Using this we can update a huge number of list items in a list. Please follow the below steps to understand the code [&hellip;]","og_url":"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-sharepoint-list-items-in-batch-using-csom\/","og_site_name":"Softree Technology","article_published_time":"2020-06-10T13:58:13+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-sharepoint-list-items-in-batch-using-csom\/#article","isPartOf":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-sharepoint-list-items-in-batch-using-csom\/"},"author":{"name":"admin","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/98740297642f06debccdcee2de84086b"},"headline":"Create SharePoint list items in batch using CSOM","datePublished":"2020-06-10T13:58:13+00:00","mainEntityOfPage":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-sharepoint-list-items-in-batch-using-csom\/"},"wordCount":329,"commentCount":0,"publisher":{"@id":"https:\/\/softreetechnology.com\/blog\/#organization"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-sharepoint-list-items-in-batch-using-csom\/#primaryimage"},"thumbnailUrl":"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2020\/06\/4.png","articleSection":["SharePoint"],"inLanguage":"en","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/softreetechnology.com\/blog\/sharepoint\/create-sharepoint-list-items-in-batch-using-csom\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-sharepoint-list-items-in-batch-using-csom\/","url":"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-sharepoint-list-items-in-batch-using-csom\/","name":"Create SharePoint list items in batch using CSOM - Softree Technology","isPartOf":{"@id":"https:\/\/softreetechnology.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-sharepoint-list-items-in-batch-using-csom\/#primaryimage"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-sharepoint-list-items-in-batch-using-csom\/#primaryimage"},"thumbnailUrl":"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2020\/06\/4.png","datePublished":"2020-06-10T13:58:13+00:00","breadcrumb":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-sharepoint-list-items-in-batch-using-csom\/#breadcrumb"},"inLanguage":"en","potentialAction":[{"@type":"ReadAction","target":["https:\/\/softreetechnology.com\/blog\/sharepoint\/create-sharepoint-list-items-in-batch-using-csom\/"]}]},{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-sharepoint-list-items-in-batch-using-csom\/#primaryimage","url":"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2020\/06\/4.png","contentUrl":"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2020\/06\/4.png"},{"@type":"BreadcrumbList","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-sharepoint-list-items-in-batch-using-csom\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/softreetechnology.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Create SharePoint list items in batch using CSOM"}]},{"@type":"WebSite","@id":"https:\/\/softreetechnology.com\/blog\/#website","url":"https:\/\/softreetechnology.com\/blog\/","name":"Softree Technology","description":"Celebrating 10+ Years in SharePoint Consulting !","publisher":{"@id":"https:\/\/softreetechnology.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/softreetechnology.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en"},{"@type":"Organization","@id":"https:\/\/softreetechnology.com\/blog\/#organization","name":"Softree Technology","url":"https:\/\/softreetechnology.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/softreetechnology.com\/blog\/wp-content\/uploads\/2023\/03\/cropped-white-logo-soft.png","contentUrl":"https:\/\/softreetechnology.com\/blog\/wp-content\/uploads\/2023\/03\/cropped-white-logo-soft.png","width":844,"height":230,"caption":"Softree Technology"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/98740297642f06debccdcee2de84086b","name":"admin","image":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6fc78c8a7aa3fb0bf43c3b9a2e3962d7?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6fc78c8a7aa3fb0bf43c3b9a2e3962d7?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/softreeconsulting.com"],"url":"https:\/\/softreetechnology.com\/blog\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts\/6144","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/comments?post=6144"}],"version-history":[{"count":0,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts\/6144\/revisions"}],"wp:attachment":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/media?parent=6144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/categories?post=6144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/tags?post=6144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}