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. var securePassword = new SecureString();
  5. foreach (char c in password)
  6. {
  7. securePassword.AppendChar(c);
  8. }
  9. SharePointOnlineCredentials onlineCredentials = new SharePointOnlineCredentials(login, securePassword);
  10. ClientContext ctx = new ClientContext(targetSiteURL);
  11. ctx.Credentials = onlineCredentials;
  12. Web web = ctx.Web;
  13. ListCreationInformation lci = new ListCreationInformation();
  14. lci.Description = "Test Library";
  15. lci.Title = "Library";
  16. lci.TemplateType = 101;
  17. List newLib = ctx.Web.Lists.Add(lci);
  18. ctx.Load(newLib);
  19. ctx.ExecuteQuery();
  20. var createLibrary = ctx.Web.Lists.GetByTitle("Library");
  21. createLibrary.ContentTypesEnabled = true;
  22. createLibrary.ListExperienceOptions = ListExperience.NewExperience;
  23. createLibrary.Update();
  24. ctx.ExecuteQuery();