{"id":58,"date":"2008-08-18T08:39:00","date_gmt":"2008-08-18T12:39:00","guid":{"rendered":"http:\/\/www.dontpapanic.com\/blog\/?p=58"},"modified":"2011-04-01T08:40:19","modified_gmt":"2011-04-01T12:40:19","slug":"adding-custom-web-part-page-templates","status":"publish","type":"post","link":"https:\/\/www.dontpapanic.com\/blog\/?p=58","title":{"rendered":"Adding Custom Web Part Page Templates"},"content":{"rendered":"<div class=\"ExternalClass1C7E139B4B2B4D02B891762795D1384D\">\n<div class=\"ExternalClassFAA098D313474EF79BD19AF3B796FFB0\">\n<p class=\"ExternalClass0BF63E7F282D470C91936878BB4F18E1\">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.&#160; I knew this was possible in SharePoint 2003 and that there was an MSDN article entitled <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms916835.aspx\"><font color=\"#000000\">Creating Custom Web Part Page Templates for Microsoft SharePoint Products and Technologies<\/font>&#160;<\/a>that explained how to do it.&#160; But since I had never tried it in 2007 I decided to investigate.<\/p>\n<p class=\"ExternalClass0BF63E7F282D470C91936878BB4F18E1\">It turns out that the answer isn&#8217;t a simple yes or no.&#160; The link on the Create page uses a page called&#160; <em>spcf.aspx<\/em> to list out the web part templates.&#160; Although you can easily add a ninth template to the list the page uses <em>owssvr.dll<\/em> to instantiate the new web part page and it seems to be hard coded to only accept templates numbered 1 through 8.&#160; So you can&#8217;t simply create a custom copy of <em>spcf.aspx<\/em> with a modified list of Web Part Page templates.&#160; But there is still a way to implement a set of Custom Web Part Page templates.<\/p>\n<p class=\"ExternalClass0BF63E7F282D470C91936878BB4F18E1\">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.&#160; The spcf.aspx file in the article download does not use <em>owssvr.dll<\/em> and is not limited to only 8 templates.&#160; The problem is that this file was designed for SharePoint 2003 and continues the look and feel of that product.&#160; You also have to make allowances for some path changes since the 2003 product.&#160; 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. <\/p>\n<p class=\"ExternalClass0BF63E7F282D470C91936878BB4F18E1\"><strong><font color=\"#ff0000\">NOTE: In addition to updating the custom creation page for a Master Page environment certain code changes were also required.&#160; You must use the custspcf.aspx code available for download from this BLOG as a starting point to make this work.<\/font><\/strong><\/p>\n<p class=\"ExternalClass0BF63E7F282D470C91936878BB4F18E1\"><strong><u><font color=\"#000080\">Steps to add Custom Web Part Page Templates<\/font><\/u><\/strong><\/p>\n<div class=\"ExternalClass0BF63E7F282D470C91936878BB4F18E1\">\n<ul>\n<li>Download custom creation page (<em>custspcf.aspx<\/em>) from <a href=\"http:\/\/www.dontpapanic.com\/download\/custspcf.aspx.txt\">here<\/a> and copy it 12 hive on your Web front end servers.&#160; The file should be copied to the following directory <strong><em>Local_drive<\/em>:\\Program Files\\Common Files\\Microsoft Shared\\Web Server Extensions\\60\\TEMPLATE\\LAYOUTS\\1033<\/strong>.&#160;&#160; (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.) <\/li>\n<li>Open the new <em>custspcf.aspx<\/em> file in Visual Studio or another suitable text\/html editor. <\/li>\n<li>Search for <em>onetidWebPartPageTemplate <\/em>in the custspcf.aspx file.&#160; This is the ID of the selection list for the Web Part Page templates.&#160; 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.&#160; If you only want two custom templates skip step 4. <\/li>\n<li>To add additional templates increment the <em>size<\/em> attribute of the <em>Select<\/em> element to the number of choices in the list and duplicate the second <em>Option<\/em> element in the list.&#160; Change the <em>name<\/em> value of the <em>Option<\/em> element using a pattern of <strong>Custom#<\/strong>, where # is the next index in the list of selections. <\/li>\n<li>Add the new custom Web Part Page template, named Custom# to match the entry in step 4, to the <strong><em>Local_drive<\/em>:\\Program Files\\Common Files\\Microsoft Shared\\Web Server Extensions\\60\\TEMPLATE\\1033\\STS\\DOCTEMP\\SMARTPGS <\/strong>directory.&#160;&#160; <\/li>\n<li>Copy an image file named Custom<em>#<\/em>.gif for each of the Web Part Page templates you wish to add where <em>#<\/em> is the number of the template in the list to <strong><em>Local_drive<\/em>:\\Program Files\\Common Files\\Microsoft Shared\\Web Server Extensions\\60\\TEMPLATE\\LAYOUTS\\1033\\IMAGES<\/strong> <\/li>\n<li>Add a Link to custspcf.aspx to the Create.aspx page stored in the <strong><em>Local_drive<\/em>:\\Program Files\\Common Files\\Microsoft Shared\\Web Server Extensions\\60\\TEMPLATE\\LAYOUTS<\/strong> directory.&#160; <strong>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. <\/strong>&#160;&#160; To add the link search for onetidWebPartPage.&#160; Go to the next tag and insert the following code block immediately after the tag, but before the start of the &quot;<strong>\/&gt;<\/strong>&quot;. <span style=\"font-family: &#39;Courier New&#39;; font-size: 10pt\"><span style=\"font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt\"><span style=\"font-family: &#39;Courier New&#39;; font-size: 10pt\"><span style=\"font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt\"><span style=\"font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt\"><\/span><\/span>\n<pre style=\"border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 872px; padding-right: 5px; height: 539px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px\"><pre style=\"background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px\">  1: <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">table<\/span> <span style=\"color: #ff0000\">style<\/span>=<span style=\"color: #0000ff\">&quot;padding: 3px 0px 3px 4px;&quot;<\/span> <span style=\"color: #ff0000\">class<\/span>=<span style=\"color: #0000ff\">&quot;ms-itemstatic&quot;<\/span> <span style=\"color: #ff0000\">onclick<\/span>=<span style=\"color: #0000ff\">&quot;javascript:NavigateInnerHref(event)&quot;<\/span> <span style=\"color: #ff0000\">onmouseover<\/span>=<span style=\"color: #0000ff\">&quot;this.className='ms-itemhover';ShowListInformation('&quot;<\/span>\n<\/pre>\n<pre style=\"background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px\">  2:   &lt;<span style=\"color: #ff0000\">SharePoint<\/span>:<span style=\"color: #ff0000\">EncodedLiteral<\/span> <span style=\"color: #ff0000\">runat<\/span>=<span style=\"color: #0000ff\">&quot;server&quot;<\/span> <span style=\"color: #ff0000\">EncodeMethod<\/span>=<span style=\"color: #0000ff\">&quot;EcmaScriptStringLiteralEncode&quot;<\/span> <span style=\"color: #ff0000\">Text<\/span>=<span style=\"color: #0000ff\">&quot;&quot;<\/span>\n<\/pre>\n<pre style=\"background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px\">  3:   &lt;%$<span style=\"color: #ff0000\">Resources<\/span>:<span style=\"color: #ff0000\">wss<\/span>,<span style=\"color: #ff0000\">viewlsts_wp_page_title<\/span>%<span style=\"color: #0000ff\">&gt;<\/span>\n<\/pre>\n<pre style=\"background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px\">  4:     &quot;\/&gt;','<span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #c71585\">SharePoint<\/span>:<span style=\"color: #800000\">EncodedLiteral<\/span> <span style=\"color: #ff0000\">runat<\/span>=<span style=\"color: #0000ff\">&quot;server&quot;<\/span> <span style=\"color: #ff0000\">EncodeMethod<\/span>=<span style=\"color: #0000ff\">&quot;EcmaScriptStringLiteralEncode&quot;<\/span> <span style=\"color: #ff0000\">Text<\/span>=<span style=\"color: #0000ff\">&quot;&quot;<\/span>&lt;%$<span style=\"color: #ff0000\">Resources<\/span>:<span style=\"color: #ff0000\">wss<\/span>,<span style=\"color: #ff0000\">viewlsts_wp_page_desc<\/span>%<span style=\"color: #0000ff\">&gt;<\/span>\n<\/pre>\n<pre style=\"background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px\">  5:       &quot;\/&gt;','\/_layouts\/images\/ltsmrtpg.gif')&quot; onmouseout=&quot;this.className='ms-itemstatic';HideListInformation()&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; width=&quot;100%&quot; border=&quot;0&quot;&gt;\n<\/pre>\n<pre style=\"background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px\">  6:       <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">tr<\/span><span style=\"color: #0000ff\">&gt;<\/span>\n<\/pre>\n<pre style=\"background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px\">  7:         <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">td<\/span> <span style=\"color: #ff0000\">valign<\/span>=<span style=\"color: #0000ff\">&quot;top&quot;<\/span> <span style=\"color: #ff0000\">nowrap<\/span>=<span style=\"color: #0000ff\">&quot;&quot;<\/span> <span style=\"color: #ff0000\">class<\/span>=<span style=\"color: #0000ff\">&quot;ms-descriptiontext&quot;<\/span> <span style=\"color: #ff0000\">style<\/span>=<span style=\"color: #0000ff\">&quot;padding-top:1px&quot;<\/span><span style=\"color: #0000ff\">&gt;<\/span>\n<\/pre>\n<pre style=\"background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px\">  8:           <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">IMG<\/span> <span style=\"color: #ff0000\">src<\/span>=<span style=\"color: #0000ff\">&quot;\/_layouts\/images\/setrect.gif&quot;<\/span> <span style=\"color: #ff0000\">width<\/span>=<span style=\"color: #0000ff\">&quot;5px&quot;<\/span> <span style=\"color: #ff0000\">height<\/span>=<span style=\"color: #0000ff\">&quot;5px&quot;<\/span> <span style=\"color: #ff0000\">alt<\/span>=<span style=\"color: #0000ff\">&quot;&quot;<\/span>\n<\/pre>\n<pre style=\"background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px\">  9:           &lt;<span style=\"color: #ff0000\">SharePoint<\/span>:<span style=\"color: #ff0000\">EncodedLiteral<\/span> <span style=\"color: #ff0000\">runat<\/span>=<span style=\"color: #0000ff\">'server'<\/span> <span style=\"color: #ff0000\">text<\/span>=<span style=\"color: #0000ff\">''<\/span>\n<\/pre>\n<pre style=\"background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px\"> 10:           &lt;%$<span style=\"color: #ff0000\">Resources<\/span>:<span style=\"color: #ff0000\">wss<\/span>,<span style=\"color: #ff0000\">viewlsts_wp_page_desc<\/span>%<span style=\"color: #0000ff\">&gt;<\/span>' EncodeMethod='HtmlEncode'\/&gt;&quot;&gt;&amp;nbsp;\n<\/pre>\n<pre style=\"background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px\"> 11:         <span style=\"color: #0000ff\">&lt;\/<\/span><span style=\"color: #800000\">td<\/span><span style=\"color: #0000ff\">&gt;<\/span>\n<\/pre>\n<pre style=\"background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px\"> 12:         <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">td<\/span> <span style=\"color: #ff0000\">valign<\/span>=<span style=\"color: #0000ff\">&quot;top&quot;<\/span> <span style=\"color: #ff0000\">width<\/span>=<span style=\"color: #0000ff\">&quot;100&quot;<\/span>% <span style=\"color: #ff0000\">class<\/span>=<span style=\"color: #0000ff\">&quot;ms-descriptiontext&quot;<\/span><span style=\"color: #0000ff\">&gt;<\/span>\n<\/pre>\n<pre style=\"background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px\"> 13:           <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">a<\/span> <span style=\"color: #ff0000\">id<\/span>=<span style=\"color: #0000ff\">&quot;onetidCustWebPartPage&quot;<\/span> <span style=\"color: #ff0000\">href<\/span>=<span style=\"color: #0000ff\">&quot;Custspcf.aspx&quot;<\/span> <span style=\"color: #ff0000\">target<\/span>=<span style=\"color: #0000ff\">&quot;_self&quot;<\/span><span style=\"color: #0000ff\">&gt;<\/span>\n<\/pre>\n<pre style=\"background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px\"> 14:             <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #c71585\">SharePoint<\/span>:<span style=\"color: #800000\">EncodedLiteral<\/span> <span style=\"color: #ff0000\">runat<\/span>=<span style=\"color: #0000ff\">&quot;server&quot;<\/span> <span style=\"color: #ff0000\">text<\/span>=<span style=\"color: #0000ff\">&quot;Custom Web Part Page&quot;<\/span> <span style=\"color: #ff0000\">EncodeMethod<\/span>=<span style=\"color: #0000ff\">'HtmlEncode'<\/span><span style=\"color: #0000ff\">\/&gt;<\/span>\n<\/pre>\n<pre style=\"background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px\"> 15:           <span style=\"color: #0000ff\">&lt;\/<\/span><span style=\"color: #800000\">a<\/span><span style=\"color: #0000ff\">&gt;<\/span>\n<\/pre>\n<pre style=\"background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px\"> 16:         <span style=\"color: #0000ff\">&lt;\/<\/span><span style=\"color: #800000\">td<\/span><span style=\"color: #0000ff\">&gt;<\/span>\n<\/pre>\n<pre style=\"background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px\"> 17:       <span style=\"color: #0000ff\">&lt;\/<\/span><span style=\"color: #800000\">tr<\/span><span style=\"color: #0000ff\">&gt;<\/span>\n<\/pre>\n<pre style=\"background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px\"> 18:     <span style=\"color: #0000ff\">&lt;\/<\/span><span style=\"color: #800000\">table<\/span><span style=\"color: #0000ff\">&gt;<\/span><\/pre>\n<p>              <\/span><\/span><\/span><\/li>\n<\/ul><\/div>\n<p style=\"margin: 0in 0in 10pt\" class=\"MsoNormal\">That&#8217;s all you need.&#160; The next time you browse to the Create page you will see a link to Custom Web Part Page.&#160; 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.&#160; Just like it did in SharePoint 2003.<\/p>\n<\/p><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>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.&#160; I knew this was possible in SharePoint 2003 and that there was &hellip; <a href=\"https:\/\/www.dontpapanic.com\/blog\/?p=58\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Adding Custom Web Part Page Templates<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[19,15],"class_list":["post-58","post","type-post","status-publish","format-standard","hentry","category-sharepoint-2007-dev","tag-development","tag-sharepoint_2007"],"_links":{"self":[{"href":"https:\/\/www.dontpapanic.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/58","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dontpapanic.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dontpapanic.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dontpapanic.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dontpapanic.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=58"}],"version-history":[{"count":1,"href":"https:\/\/www.dontpapanic.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/58\/revisions"}],"predecessor-version":[{"id":140,"href":"https:\/\/www.dontpapanic.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/58\/revisions\/140"}],"wp:attachment":[{"href":"https:\/\/www.dontpapanic.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=58"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dontpapanic.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=58"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dontpapanic.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=58"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}