{"id":961,"date":"2019-03-26T07:23:28","date_gmt":"2019-03-26T07:23:28","guid":{"rendered":"http:\/\/blog.softreeconsulting.com\/?p=961"},"modified":"2019-03-26T07:23:28","modified_gmt":"2019-03-26T07:23:28","slug":"set-list-properties-by-webrequest","status":"publish","type":"post","link":"https:\/\/softreetechnology.com\/blog\/sharepoint\/set-list-properties-by-webrequest\/","title":{"rendered":"Set List Properties By WebRequest"},"content":{"rendered":"\n<p>There are many ways in CSOM to set the list properties of a SharePoint site but there are a few properties which we can&#8217;t set directly from list object. In this blog, I will explain how to set those properties using WebRequest.<\/p>\n\n\n\n<p>There are many ways in CSOM to set the list properties of a SharePoint site. But there are a few properties which we can&#8217;t set directly from the list object. In this blog, I will explain how to find those using the WebRequest.example:-offline client availability, major version limit, major with mino version limit.<\/p>\n\n\n\n<p>This below-mentioned code sample will help us to set those properties which we cannot access directly from the list object.<\/p>\n\n\n\n<p><strong>The code block for this is as mentioned below :<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\nusing Microsoft.SharePoint.Client;\nusing System.Net;\nusing System.Security;\nusing Microsoft.SharePoint.Client.Utilities;\nusing System.IO;\n\nnamespace EditListProperties\n{\nclass EditListPropertiesByWebRequest\n{\npublic static string HEADER_CONTENT_APP = &amp;amp;quot;application\/x-vermeer-urlencoded&amp;amp;quot;;\npublic static string USER_AGENT_APP = &amp;amp;quot;FrontPage&amp;amp;quot;;\npublic static string MESSAGE_SUCCESS_APP = &amp;amp;quot;message=successfully&amp;amp;quot;;\npublic static string MESSAGE_CONFLICT_APP = &amp;amp;quot;msg=Save Conflict&amp;amp;quot;;\npublic static string ENABLE_OFFLINE_CLIENT_AVAILABILITY_APP = &amp;amp;quot;&amp;amp;amp;ExcludeFromOfflineClient=False&amp;amp;quot;;\npublic static string DISABLE_OFFLINE_CLIENT_AVAILABILITY_APP = &amp;amp;quot;&amp;amp;amp;ExcludeFromOfflineClient=True&amp;amp;quot;;\npublic static string MAJOR_VERSION_LIMIT_APP = &amp;amp;quot;&amp;amp;amp;MajorVersionLimit=&amp;amp;quot;;\npublic static string MAJOR_VERSION_WITH_MINOR_APP = &amp;amp;quot;&amp;amp;amp;MajorWithMinorVersionsLimit=&amp;amp;quot;;\nstatic void Main(string[] args)\n{\nstring listName = &amp;amp;quot;CopyDoc&amp;amp;quot;;\nstring username = string.Empty;\nstring password = string.Empty;\nNetworkCredential credentials = null;\nList list = null;\nstring query = string.Empty;\n\ntry\n{\nusername = &amp;amp;quot;userName&amp;amp;quot;;\npassword = &amp;amp;quot;******&amp;amp;quot;;\n\nClientContext ctx = new ClientContext(&amp;amp;quot;siteUrl&amp;amp;quot;); \/\/creating ClientContext from given SharePoint Site\ncredentials = new NetworkCredential(username, password); \/\/creating creadential object for SharePoint site.\n\nctx.Credentials = credentials;\nWeb web = ctx.Web;\nlist = ctx.Web.Lists.GetByTitle(listName);\nctx.Load(list, l =&amp;amp;gt; l.EnableVersioning);\nctx.ExecuteQuery();\n}\ncatch (Exception ex) { }\n\ntry\n{\n\/\/if we want to &amp;amp;quot;SET OFFLINE CLIENT AVAILABILITY&amp;amp;quot;\nstring value = string.Empty;\nvalue = &amp;amp;quot;Enable&amp;amp;quot;; \/\/We can change it to Enable or Disable accoring to requirement\n\nif (value == &amp;amp;quot;Enable&amp;amp;quot;) \/\/ if we want it to be enabled\n{\nquery += ENABLE_OFFLINE_CLIENT_AVAILABILITY_APP;\n}\nelse if (value == &amp;amp;quot;Disable&amp;amp;quot;) \/\/ if we want it to be disabled\n{\nquery += DISABLE_OFFLINE_CLIENT_AVAILABILITY_APP;\n}\n\n\/\/if we want to &amp;amp;quot;SET MAJOR VERSION LIMIT&amp;amp;quot;\nvalue = string.Empty;\nvalue = &amp;amp;quot;10&amp;amp;quot;; \/\/We can change it to any intiger accoring to requirement\nlist.EnableVersioning = true;\nlist.Update();\nquery += MAJOR_VERSION_LIMIT_APP + value;\n\n\/\/if we want to &amp;amp;quot;SET MAJOR WITH MINOR VERSIONS LIMIT&amp;amp;quot;\nvalue = string.Empty;\nvalue = &amp;amp;quot;5&amp;amp;quot;; \/\/We can change it to any intiger accoring to requirement\nlist.EnableVersioning = true;\nlist.Update();\nquery += MAJOR_VERSION_WITH_MINOR_APP + value;\n\nGetHttpWebRequest(query, credentials);\n\n}\ncatch (Exception er) { }\n}\n\n#region GetWebRequest\n\/\/\/ &amp;amp;lt;summary&amp;amp;gt;\n\/\/\/\n\/\/\/ &amp;amp;lt;\/summary&amp;amp;gt;\n\/\/\/ &amp;amp;lt;param name=&amp;amp;quot;query&amp;amp;quot;&amp;amp;gt;&amp;amp;lt;\/param&amp;amp;gt;\n\/\/\/ &amp;amp;lt;param name=&amp;amp;quot;credential&amp;amp;quot;&amp;amp;gt;&amp;amp;lt;\/param&amp;amp;gt;\nprivate static void GetHttpWebRequest(string query, NetworkCredential credential)\n{\ntry\n{\nHttpWebRequest request = (HttpWebRequest)WebRequest.Create(query);\nrequest.Method = &amp;amp;quot;POST&amp;amp;quot;;\nrequest.Headers[&amp;amp;quot;Content&amp;amp;quot;] = HEADER_CONTENT_APP;\nrequest.Headers[&amp;amp;quot;X-Vermeer-Content-Type&amp;amp;quot;] = HEADER_CONTENT_APP;\nrequest.UserAgent = USER_AGENT_APP;\nrequest.UseDefaultCredentials = false;\nrequest.KeepAlive = true;\n\nrequest.Credentials = credential;\n\nusing (System.IO.Stream requestStream = request.GetRequestStream())\n{\nGetWebResponse(request);\n}\n}\ncatch (Exception er) { }\n}\n#endregion\n\n#region GetResponse\n\/\/\/ &amp;amp;lt;summary&amp;amp;gt;\n\/\/\/\n\/\/\/ &amp;amp;lt;\/summary&amp;amp;gt;\n\/\/\/ &amp;amp;lt;param name=&amp;amp;quot;webRequest&amp;amp;quot;&amp;amp;gt;&amp;amp;lt;\/param&amp;amp;gt;\n\/\/\/ &amp;amp;lt;returns&amp;amp;gt;&amp;amp;lt;\/returns&amp;amp;gt;\nprivate static string GetWebResponse(HttpWebRequest webRequest)\n{\nstring responseString = string.Empty;\nusing (WebResponse webResponse = webRequest.GetResponse())\n{\nusing (StreamReader reader = new StreamReader(webResponse.GetResponseStream()))\n{\nresponseString = reader.ReadToEnd();\nbyte[] fileBuffer = Encoding.UTF8.GetBytes(responseString);\n}\n}\n\nif ((responseString.IndexOf(MESSAGE_SUCCESS_APP) &amp;amp;lt; 0) &amp;amp;amp;&amp;amp;amp; (responseString.IndexOf(MESSAGE_CONFLICT_APP) &amp;amp;lt; 0))\n{\nthrow new Exception(responseString);\n}\nreturn responseString;\n}\n#endregion\n}\n}<\/code><\/pre>\n\n\n\n<p>In this blog, I have explained how you can set the properties of a <a href=\"https:\/\/www.softreetechnology.com\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"SharePoint (opens in a new tab)\">SharePoint<\/a> list using WebRequest. I hope this information will help you out in a few scenarios.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are many ways in CSOM to set the list properties of a SharePoint site but there are a few properties which we can&#8217;t set directly from list object. In this blog, I will explain how to set those properties using WebRequest. There are many ways in CSOM to set the list properties of a SharePoint site. But there are [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[129,43],"tags":[227,228],"class_list":["post-961","post","type-post","status-publish","format-standard","hentry","category-all","category-sharepoint","tag-set-list-properties","tag-set-list-properties-by-httprequest"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Set List Properties By WebRequest - 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\/set-list-properties-by-webrequest\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Set List Properties By WebRequest - Softree Technology\" \/>\n<meta property=\"og:description\" content=\"There are many ways in CSOM to set the list properties of a SharePoint site but there are a few properties which we can&#8217;t set directly from list object. In this blog, I will explain how to set those properties using WebRequest. There are many ways in CSOM to set the list properties of a SharePoint site. But there are [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/softreetechnology.com\/blog\/sharepoint\/set-list-properties-by-webrequest\/\" \/>\n<meta property=\"og:site_name\" content=\"Softree Technology\" \/>\n<meta property=\"article:published_time\" content=\"2019-03-26T07:23:28+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=\"4 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Set List Properties By WebRequest - 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\/set-list-properties-by-webrequest\/","og_locale":"en_US","og_type":"article","og_title":"Set List Properties By WebRequest - Softree Technology","og_description":"There are many ways in CSOM to set the list properties of a SharePoint site but there are a few properties which we can&#8217;t set directly from list object. In this blog, I will explain how to set those properties using WebRequest. There are many ways in CSOM to set the list properties of a SharePoint site. But there are [&hellip;]","og_url":"https:\/\/softreetechnology.com\/blog\/sharepoint\/set-list-properties-by-webrequest\/","og_site_name":"Softree Technology","article_published_time":"2019-03-26T07:23:28+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/set-list-properties-by-webrequest\/#article","isPartOf":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/set-list-properties-by-webrequest\/"},"author":{"name":"admin","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/98740297642f06debccdcee2de84086b"},"headline":"Set List Properties By WebRequest","datePublished":"2019-03-26T07:23:28+00:00","mainEntityOfPage":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/set-list-properties-by-webrequest\/"},"wordCount":161,"commentCount":0,"publisher":{"@id":"https:\/\/softreetechnology.com\/blog\/#organization"},"keywords":["set list properties","set list properties by httprequest"],"articleSection":["All","SharePoint"],"inLanguage":"en","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/softreetechnology.com\/blog\/sharepoint\/set-list-properties-by-webrequest\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/set-list-properties-by-webrequest\/","url":"https:\/\/softreetechnology.com\/blog\/sharepoint\/set-list-properties-by-webrequest\/","name":"Set List Properties By WebRequest - Softree Technology","isPartOf":{"@id":"https:\/\/softreetechnology.com\/blog\/#website"},"datePublished":"2019-03-26T07:23:28+00:00","breadcrumb":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/set-list-properties-by-webrequest\/#breadcrumb"},"inLanguage":"en","potentialAction":[{"@type":"ReadAction","target":["https:\/\/softreetechnology.com\/blog\/sharepoint\/set-list-properties-by-webrequest\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/set-list-properties-by-webrequest\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/softreetechnology.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Set List Properties By WebRequest"}]},{"@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\/961","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=961"}],"version-history":[{"count":0,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts\/961\/revisions"}],"wp:attachment":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/media?parent=961"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/categories?post=961"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/tags?post=961"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}