Stack Exchange
Creating Library from custom template
I have written some code which saves a Doc Lib as a template. I am wanting to create an identical copy of how the Doc Lib is set up content types, views etc but none of the files inside the library.
However my code below only creates a OOTB Document Library and i am confused why. Below is my code:
                var tSP = new Tenant(clientContext);
                tSP.SetSiteProperties(web.Url, noScriptSite: false);
                List list = web.GetListByTitle("Library 1");
                permitSite.Load(list);
                permitSite.ExecuteQuery();
                var listid = list.Id;
                list.SaveAsTemplate("Lib", "Lib", "", false);
                list.Update();
                permitSite.ExecuteQuery();
                var site = permitSite.Site;
                permitSite.Load(site);
                permitSite.ExecuteQuery();
               


                ListTemplate listTemplate = site.GetCustomListTemplates(site.RootWeb).GetByName("Lib");
                permitSite.Load(listTemplate);
                permitSite.ExecuteQuery();

                ListCreationInformation listCreationInfo;

                
                listCreationInfo = new ListCreationInformation();
                listCreationInfo.Title = newLibraryTitle;
                listCreationInfo.Url = newLibraryURL;
                listCreationInfo.TemplateFeatureId = listTemplate.FeatureId;
                listCreationInfo.TemplateType = listTemplate.ListTemplateTypeKind;
               
                var newlist = web.Lists.Add(listCreationInfo);
                newlist.Update();
                permitSite.Load(newlist);
                permitSite.ExecuteQuery();
                tSP.SetSiteProperties(web.Url, noScriptSite: true);
                clientContext.ExecuteQuery();

Thanks in advance :)

Download the source library template without the content name as something like "custom template without the content", now in your code use this template. And make sure in target site where you are creating this new list/library must have all site columns and the content type.
