Below is the function to save as template in
sharepoint site programmatically.
Parameters
strSiteURL: send the site url in this parameter
strListName:send the ListName of which template you want to create.
public void CreateTemplate(string strSiteURL,string strListName)
{
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 strbkpTemplateName = "bkp" + strListName + ".stp";
list.SaveAsTemplate(strbkpTemplateName, strbkpTemplateName.Replace(".stp",""), "Description", true);
list.Update();
oSPWeb.AllowUnsafeUpdates = false;
}
oSPsite.AllowUnsafeUpdates = false;
}
});
}

Harish SrikanthrajPosted Aug 21, 2017, 3:32 AM
I'm using CSOM,need to add dll for SaveAsTemplate?
Adnan ShamimPosted Aug 12, 2015, 7:24 AM
Can you confirm if we can create list templates through CSOM in SharePOint 2013? i am looking to create a site template from CSOM.... i dont see relevant functions in CSOM.