Save List as Template SharePoint 2013 Programmatically

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.

[AdSense-A]

 SPSecurity.RunWithElevatedPrivileges(delegate
            {
                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);
                        list.Update();
                        oSPWeb.AllowUnsafeUpdates = false;
                    }
                    oSPsite.AllowUnsafeUpdates = false;
                }
            });

 

Below is the function to save as template in SharePoint site programmatically.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: Content is protected !!