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.
- var SiteURL = @"https://myssharepoint.com/sites/";
- var login = "Laks@***.onmicrosoft.com";
- var password = "****";
-
- var securePassword = new SecureString();
-
- foreach (char c in password)
- {
- securePassword.AppendChar(c);
- }
- SharePointOnlineCredentials onlineCredentials = new SharePointOnlineCredentials(login, securePassword);
-
- ClientContext ctx = new ClientContext(targetSiteURL);
- ctx.Credentials = onlineCredentials;
- Web web = ctx.Web;
-
- ListCreationInformation lci = new ListCreationInformation();
- lci.Description = "Test Library";
- lci.Title = "Library";
- lci.TemplateType = 101;
-
- List newLib = ctx.Web.Lists.Add(lci);
- ctx.Load(newLib);
- ctx.ExecuteQuery();
-
- var createLibrary = ctx.Web.Lists.GetByTitle("Library");
- createLibrary.ContentTypesEnabled = true;
- createLibrary.ListExperienceOptions = ListExperience.NewExperience;
- createLibrary.Update();
- ctx.ExecuteQuery();