4

For creating a list template programmatically by using server object, I'm using the SaveAsTemplate() function.

SPSecurity.RunWithElevatedPrivileges(delegate
{
  using (SPSite oSPsite = new SPSite(strSiteURL))
  {
    oSPsite.AllowUnsafeUpdates = true;
    using (SPWeb oSPWeb = oSPsite.OpenWeb())
    {
      oSPWeb.AllowUnsafeUpdates = true;

      SPList list = oSPWeb.Lists[strListName];
      string bkpTemplateName = "bkp" + strListName + ".stp";
      list.SaveAsTemplate(bkpTemplateName, bkpTemplateName.Replace(".stp",""), "Description", true);

      list.Update();
      oSPWeb.AllowUnsafeUpdates = false;
    }
    oSPsite.AllowUnsafeUpdates = false;
  }
});

But, is there a way to do the same by using CSOM?

5

The method SaveAsTemplate is not exposed in CSOM API, there is a general suggestion opened: Expose List.SaveAsTemplate() for CSOM API

Basically you can create lists using already existing custom templates, but programmatically you cannot create new ones.

Site.GetCustomListTemplates(web);
Web.ListTemplates

What you can do is define the list schema xml and use it every time you have to create a new list programmatically, using the ListCreationInformation CustomSchemaXml property.

  • but exporting list schema to XML doesnt give us the data, it just just gives the schema , right? STP gives us the whole thing. Just confirming. – Rohit Nov 24 '15 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.