Articles about European Sharepoint Hosting Service
SharePoint 2013 Hosting – HostForLIFE.eu :: Set List Properties By WebRequest
There are many ways in CSOM to set the list properties of a SharePoint site but there are a few properties which we can’t set directly from list object. In this blog, I will explain how to set those properties using WebRequest, for example: offline client availability, major version limit, and major with minor version limit.
This below-mentioned code sample will help us to set those properties which we cannot access directly from the list object.
The code block for this is as mentioned below,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.SharePoint.Client; using System.Net; using System.Security; using Microsoft.SharePoint.Client.Utilities; using System.IO; namespace EditListProperties { class EditListPropertiesByWebRequest { public static string HEADER_CONTENT_APP = "application/x-vermeer-urlencoded"; public static string USER_AGENT_APP = "FrontPage"; public static string MESSAGE_SUCCESS_APP = "message=successfully"; public static string MESSAGE_CONFLICT_APP = "msg=Save Conflict"; public static string ENABLE_OFFLINE_CLIENT_AVAILABILITY_APP = "&ExcludeFromOfflineClient=False"; public static string DISABLE_OFFLINE_CLIENT_AVAILABILITY_APP = "&ExcludeFromOfflineClient=True"; public static string MAJOR_VERSION_LIMIT_APP = "&MajorVersionLimit="; public static string MAJOR_VERSION_WITH_MINOR_APP = "&MajorWithMinorVersionsLimit="; static void Main(string[] args) { string listName = "CopyDoc"; string username = string.Empty; string password = string.Empty; NetworkCredential credentials = null; List list = null; string query = string.Empty; try { username = "userName"; password = "******"; ClientContext ctx = new ClientContext("siteUrl"); //creating ClientContext from given SharePoint Site credentials = new NetworkCredential(username, password); //creating creadential object for SharePoint site. ctx.Credentials = credentials; Web web = ctx.Web; list = ctx.Web.Lists.GetByTitle(listName); ctx.Load(list, l => l.EnableVersioning); ctx.ExecuteQuery(); } catch (Exception ex) {} try { //if we want to "SET OFFLINE CLIENT AVAILABILITY" string value = string.Empty; value = "Enable"; //We can change it to Enable or Disable accoring to requirement if (value == "Enable") // if we want it to be enabled { query += ENABLE_OFFLINE_CLIENT_AVAILABILITY_APP; } else if (value == "Disable") // if we want it to be disabled { query += DISABLE_OFFLINE_CLIENT_AVAILABILITY_APP; } //if we want to "SET MAJOR VERSION LIMIT" value = string.Empty; value = "10"; //We can change it to any intiger accoring to requirement list.EnableVersioning = true; list.Update(); query += MAJOR_VERSION_LIMIT_APP + value; //if we want to "SET MAJOR WITH MINOR VERSIONS LIMIT" value = string.Empty; value = "5"; //We can change it to any intiger accoring to requirement list.EnableVersioning = true; list.Update(); query += MAJOR_VERSION_WITH_MINOR_APP + value; GetHttpWebRequest(query, credentials); } catch (Exception er) {} } #region GetWebRequest /// <summary> /// /// </summary> /// <param name="query"></param> /// <param name="credential"></param> private static void GetHttpWebRequest(string query, NetworkCredential credential) { try { HttpWebRequest request = (HttpWebRequest) WebRequest.Create(query); request.Method = "POST"; request.Headers["Content"] = HEADER_CONTENT_APP; request.Headers["X-Vermeer-Content-Type"] = HEADER_CONTENT_APP; request.UserAgent = USER_AGENT_APP; request.UseDefaultCredentials = false; request.KeepAlive = true; request.Credentials = credential; using(System.IO.Stream requestStream = request.GetRequestStream()) { GetWebResponse(request); } } catch (Exception er) {} } #endregion #region GetResponse /// <summary> /// /// </summary> /// <param name="webRequest"></param> /// <returns></returns> private static string GetWebResponse(HttpWebRequest webRequest) { string responseString = string.Empty; using(WebResponse webResponse = webRequest.GetResponse()) { using(StreamReader reader = new StreamReader(webResponse.GetResponseStream())) { responseString = reader.ReadToEnd(); byte[] fileBuffer = Encoding.UTF8.GetBytes(responseString); } } if ((responseString.IndexOf(MESSAGE_SUCCESS_APP) < 0) && (responseString.IndexOf(MESSAGE_CONFLICT_APP) < 0)) { throw new Exception(responseString); } return responseString; }#endregion } } |
In this blog, I have explained how you can set the properties of a SharePoint list using WebRequest. I hope this information will help you out in a few scenarios.
SharePoint 2013 Hosting Recommendation
HostForLIFE.eu’s SharePoint 2013 Hosting solution offers a comprehensive feature set that is easy-to-use for new users, yet powerful enough for the most demanding web developer expert. Hosted SharePoint Foundation 2013 is the premiere web-based collaboration and productivity enhancement tool on the market today. With SharePoint 2013 Foundation, you can quickly access and manage documents and information anytime, anywhere though a Web browser in a secure and user friendly way. SharePoint hosting services start at only at €9.99/mo, allowing you to take advantage of the robust feature set for a small business price. HostForLIFE.eu offers a variety of hosted SharePoint Foundation 2013 plans as well as dedicated SharePoint 2013 Foundation options
Print article | This entry was posted by Peter on March 28, 2019 at 7:09 am, and is filed under European SharePoint 2013 Hosting. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |