How To Create A Modern Document Library In SharePoint 2010/2013/Online Using CSOM

Hello SharePointers,

Modern Document library experience in SharePoint is the most talked about feature nowadays. You can switch back to the classic experience anytime but the modern list/document gives you a fresh & new look and much more added functionality. Below is the CSOM to create a document library in Sharepoint online using CSOM.

ListExperience.NewExperience is the property we need to set up. 

  1. var SiteURL = @"https://myssharepoint.com/sites/";  
  2. var login = "Laks@***.onmicrosoft.com";  
  3. var password = "****";  
  4.   
  5. var securePassword = new SecureString();  
  6.   
  7. foreach (char c in password)  
  8. {  
  9.     securePassword.AppendChar(c);  
  10. }  
  11. SharePointOnlineCredentials onlineCredentials = new SharePointOnlineCredentials(login, securePassword);  
  12.   
  13. ClientContext ctx = new ClientContext(targetSiteURL);  
  14. ctx.Credentials = onlineCredentials;  
  15. Web web = ctx.Web;  
  16.   
  17. ListCreationInformation lci = new ListCreationInformation();  
  18. lci.Description = "Test Library";  
  19. lci.Title = "Library";  
  20. lci.TemplateType = 101;  
  21.   
  22. List newLib = ctx.Web.Lists.Add(lci);  
  23. ctx.Load(newLib);  
  24. ctx.ExecuteQuery();  
  25.   
  26. var createLibrary = ctx.Web.Lists.GetByTitle("Library");  
  27. createLibrary.ContentTypesEnabled = true;  
  28. createLibrary.ListExperienceOptions = ListExperience.NewExperience;  
  29. createLibrary.Update();  
  30. ctx.ExecuteQuery();
X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now