Save List as Template SharePoint 2013 Programmatically:-
In this post, I will explain to you how to Save List as Template SharePoint 2013 Programmatically. And when we need to save List as a template.If you need to create the same list on another site then you need to Save List as Template. If want to manually then SharePoint provide you functionality but if need to save the list as a template in bulk, At that time you will write some code.
PWAPATH: send the site URL in this parameter
ListName: send the ListName of which template you want to create.
string PWAPATH = SPContext.Current.Web.Url;
using (SPSite oSPsite = new SPSite(PWAPATH))
oSPsite.AllowUnsafeUpdates = true;
using (SPWeb oSPWeb = oSPsite.OpenWeb())
oSPWeb.AllowUnsafeUpdates = true;
SPList list = oSPWeb.Lists[ListName];
string strbkpTemplateName = ListName + ".stp";
list.SaveAsTemplate(strbkpTemplateName, strbkpTemplateName.Replace(".stp", ""), "Description", true);
oSPWeb.AllowUnsafeUpdates = false;
oSPsite.AllowUnsafeUpdates = false;
Below is the function to save as template in SharePoint site programmatically.