Adding Custom Web Part Page Templates

I was recently asked whether it was possible to add custom Web Part Page templates to the Create page in SharePoint 2007 or whether the interface was limited to the eight existing Web Part Pages and required you to replace one of those.  I knew this was possible in SharePoint 2003 and that there was an MSDN article entitled Creating Custom Web Part Page Templates for Microsoft SharePoint Products and Technologies that explained how to do it.  But since I had never tried it in 2007 I decided to investigate.

It turns out that the answer isn’t a simple yes or no.  The link on the Create page uses a page called  spcf.aspx to list out the web part templates.  Although you can easily add a ninth template to the list the page uses owssvr.dll to instantiate the new web part page and it seems to be hard coded to only accept templates numbered 1 through 8.  So you can’t simply create a custom copy of spcf.aspx with a modified list of Web Part Page templates.  But there is still a way to implement a set of Custom Web Part Page templates.

Interestingly enough if you follow the directions in the SharePoint 2003 MSDN article mentioned above and use the files downloaded from the article you can make this work.  The spcf.aspx file in the article download does not use owssvr.dll and is not limited to only 8 templates.  The problem is that this file was designed for SharePoint 2003 and continues the look and feel of that product.  You also have to make allowances for some path changes since the 2003 product.  So I decided to update the custom page to use a SharePoint 2007 Master Page and relist the steps in the article with modifications for the SharePoint 2007 environment.

NOTE: In addition to updating the custom creation page for a Master Page environment certain code changes were also required.  You must use the custspcf.aspx code available for download from this BLOG as a starting point to make this work.

Steps to add Custom Web Part Page Templates

  • Download custom creation page (custspcf.aspx) from here and copy it 12 hive on your Web front end servers.  The file should be copied to the following directory Local_drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\TEMPLATE\LAYOUTS\1033.   (Note: If you are running on a server installed in a language other than English replace 1033 with the Language Code Identifier for your language.)
  • Open the new custspcf.aspx file in Visual Studio or another suitable text/html editor.
  • Search for onetidWebPartPageTemplate in the custspcf.aspx file.  This is the ID of the selection list for the Web Part Page templates.  There are two selections already included for the file, one for Custom1.aspx (set to be the default selection) and the other for Custom2.aspx.  If you only want two custom templates skip step 4.
  • To add additional templates increment the size attribute of the Select element to the number of choices in the list and duplicate the second Option element in the list.  Change the name value of the Option element using a pattern of Custom#, where # is the next index in the list of selections.
  • Add the new custom Web Part Page template, named Custom# to match the entry in step 4, to the Local_drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\TEMPLATE\1033\STS\DOCTEMP\SMARTPGS directory.  
  • Copy an image file named Custom#.gif for each of the Web Part Page templates you wish to add where # is the number of the template in the list to Local_drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\TEMPLATE\LAYOUTS\1033\IMAGES
  • Add a Link to custspcf.aspx to the Create.aspx page stored in the Local_drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\TEMPLATE\LAYOUTS directory.  NOTE: You may need to put a copy of this page back in the future so make sure you have a backup copy before editing it.    To add the link search for onetidWebPartPage.  Go to the next tag and insert the following code block immediately after the tag, but before the start of the "/>".
      1: <table style="padding: 3px 0px 3px 4px;" class="ms-itemstatic" onclick="javascript:NavigateInnerHref(event)" onmouseover="this.className='ms-itemhover';ShowListInformation('"
    
      2:   <SharePoint:EncodedLiteral runat="server" EncodeMethod="EcmaScriptStringLiteralEncode" Text=""
    
      3:   <%$Resources:wss,viewlsts_wp_page_title%>
    
      4:     "/>','<SharePoint:EncodedLiteral runat="server" EncodeMethod="EcmaScriptStringLiteralEncode" Text=""<%$Resources:wss,viewlsts_wp_page_desc%>
    
      5:       "/>','/_layouts/images/ltsmrtpg.gif')" onmouseout="this.className='ms-itemstatic';HideListInformation()" cellspacing="0" cellpadding="0" width="100%" border="0">
    
      6:       <tr>
    
      7:         <td valign="top" nowrap="" class="ms-descriptiontext" style="padding-top:1px">
    
      8:           <IMG src="/_layouts/images/setrect.gif" width="5px" height="5px" alt=""
    
      9:           <SharePoint:EncodedLiteral runat='server' text=''
    
     10:           <%$Resources:wss,viewlsts_wp_page_desc%>' EncodeMethod='HtmlEncode'/>">&nbsp;
    
     11:         </td>
    
     12:         <td valign="top" width="100"% class="ms-descriptiontext">
    
     13:           <a id="onetidCustWebPartPage" href="Custspcf.aspx" target="_self">
    
     14:             <SharePoint:EncodedLiteral runat="server" text="Custom Web Part Page" EncodeMethod='HtmlEncode'/>
    
     15:           </a>
    
     16:         </td>
    
     17:       </tr>
    
     18:     </table>

That’s all you need.  The next time you browse to the Create page you will see a link to Custom Web Part Page.  When you click that link you will see a page that looks like the regular creation page for Web Part Pages, but this one will have your custom templates on it. Even better you will be able to add more than 8 to the list and it will continue to work.  Just like it did in SharePoint 2003.

Published by

Paul Papanek Stork

I am a SharePoint MVP who has specialized in Microsoft products since the mid-1990s. As a "Jack of all Trades" I have developed expertise as a network administrator, developer, and DBA. I works as a consultant/trainer where my breadth of knowledge makes me ideally suited to combine Administrative, Development, and SharePoint Designer topics. My 20+ years of experience and broad background make me a much sought after resource for SharePoint questions that cross traditional boundaries. I was a contributing author to the Developer's Guide to Windows SharePoint Services v3 Platform and the SharePoint Server 2007 Deployment Best Practices. My most recent book, the MCTS Windows SharePoint Services 3.0 Configuration Study Guide: Exam 70-631, was released in October, 2009.

One thought on “Adding Custom Web Part Page Templates”

Leave a Reply

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