1

Is it possible to create a custom web part page template in share point team site?

The default web part page layout resides in 14 hive for team sites.

I have a requirement to create a custom web part page template which will have a quick launch and blank content editor web part attached.Later it will be added through custom action and used for creating new page based on this template.

Site is SharePoint OOTB team site. Can anyone shed some light on this?

Thanks.

  • To begin with, why do you create a web part page template? I would recommend to create a page layout using the pages library but you will need to activate the publishing feature and i know that SP foundation does not have one. May be you should upgrade from foundation and follow how it should be done in the best practice. – Deepu Nair Feb 3 '16 at 10:35
  • Thnx Deepu.But this I cant do.as mentioned in question it is on team site because of other reasons.I know that having activated publishing infrastructure feature this can be easily achieved. – user13408 Feb 3 '16 at 10:43
1

I see that all default webpart page layouts reside in below layout path

C:\Program Files\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\1033\STS\DOCTEMP\SMARTPGS\

So in this path I will add my one page layout.Then add below code to create page based on the layout.

string newFilename = textbox1.text;
string templateFilename = "newpagelayout.aspx";
string hive = SPUtility.GetGenericSetupPath("TEMPLATE\\1033\\STS\\DOCTEMP\\SMARTPGS\\");
FileStream stream = new FileStream(hive + templateFilename, FileMode.Open);
using (SPSite site = new SPSite(url))
using (SPWeb web = site.OpenWeb())
{
    SPFolder libraryFolder = web.GetFolder("<library name>");
    SPFileCollection files = libraryFolder.Files;
    SPFile newFile = files.Add(newFilename, stream);
}

If anyone has used other approaches/idea feel free to share.

Your Answer

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