Document Library Template Selector

This great tip was devised by my on a previous contract. I needed a Document Library list template that had more than the normal 1 Document Template. I took the drop down code and changed the Add Document link to show a choice of document templates. I hope this is useful to others.
 
Template Selector

 

1. Implementing the Document Library Template Selector
1.1. Add Custom Document Template

  • Add the following documents to the DOCTEMP\Word folder of the Site
    Definition
    • Business Case.doc
    • Communications Plan.doc
    • End Project Report.doc
    • Project Initiation Document.doc

1.2. Create New DocumentTemplate

  • Edit the Site Definiton Onet.XML File
    • At the bottom of the DocumentTemplates Element add the following:

<DocumentTemplate DisplayName=”Project Document Templates” Type=”1001″ Description=”A Collection of Templates for Project Manangement.”>   <DocumentTemplateFiles>       <DocumentTemplateFile Name=”doctemp\word\wdtmpl.doc” TargetName=”Forms/template.doc” Default=”TRUE”/>       <DocumentTemplateFile Name=”doctemp\word\BusinessCase.doc” TargetName=”Forms/Business Case.doc”/>       <DocumentTemplateFile Name=”doctemp\word\CommunicationPlan.doc” TargetName=”Forms/CommunicationPlan.doc” />       <DocumentTemplateFile Name=”doctemp\word\EndProjectReport.doc” TargetName=”Forms/EndProjectReport.doc” />       <DocumentTemplateFile Name=”doctemp\word\ProjectInitiationDocument.doc” TargetName=”Forms/ProjectInitiationDocument.doc” />   </DocumentTemplateFiles></DocumentTemplate> 

1.3. Create Project Document Library List Template

  • Copy DOCLIB List definition, call it PMDOCLIB

1.4. Customise Project Doc Lib Toolbar New Document links

  • In PMDOCLIB
    • Edit SCHEMA.XML
    • Remove the original Field Element and replace with: 

<Field Type=”Text” Name=”Title” ShowInNewForm=”TRUE” ShowInFileDlg=”TRUE” DisplayName=”Title” Sealed=”TRUE”></Field><Field Type=”Boolean” Name=”BusinessCase” ShowInNewForm=”TRUE” ShowInFileDlg=”TRUE” DisplayName=”Business Case” Sealed=”FALSE”><Default>0</Default></Field><Field Type=”Boolean” Name=”CommunicationPlan” ShowInNewForm=”TRUE” ShowInFileDlg=”TRUE” DisplayName=”Communication Plan” Sealed=”FALSE”><Default>0</Default></Field><Field Type=”Boolean” Name=”EndProjectReport” ShowInNewForm=”TRUE” ShowInFileDlg=”TRUE” DisplayName=”End Project Report” Sealed=”FALSE”><Default>0</Default></Field><Field Type=”Boolean” Name=”RequirementsMgt” ShowInNewForm=”TRUE” ShowInFileDlg=”TRUE” DisplayName=”Requirements Mgt” Sealed=”FALSE”><Default>0</Default></Field><Field Type=”Boolean” Name=”PID” ShowInNewForm=”TRUE” ShowInFileDlg=”TRUE” DisplayName=”PID” Sealed=”FALSE”><Default>0</Default></Field><Field Type=”Choice” Name=”Status” ShowInNewForm=”TRUE” ShowInFileDlg=”TRUE” DisplayName=”Status” Sealed=”FALSE”><CHOICES>  <CHOICE>Draft</CHOICE>  <CHOICE>Release</CHOICE>  <CHOICE>Archive</CHOICE></CHOICES><Default>Draft</Default></Field>

    • Rename the current definition of createNewDocument to createNewDocumentCustom
    • Change the createNewDocument function definition to be:

function ]]></HTML><GetVar Name=”WPQ”/><HTML><![CDATA[createNewDocument(){  createNewDocumentCustom(”)}

    • Change the line:

strTemplate = ]]></HTML>   <ScriptQuote><ListProperty Default=”Word.Document.8″ Select=”TemplateUrl”/></ScriptQuote><HTML><![CDATA[;

    • To:

var strTemplate;if(strTemplate != ”){  strTemplate = chosenTemplate}else{  strTemplate = ]]></HTML>  <ScriptQuote><ListProperty Default=”Word.Document.8″ Select=”TemplateUrl”/></ScriptQuote><HTML><![CDATA[;}

    • Change New Document toolbar cells to be: (change this for
      the 2 views, with DisplayName All Documents and Explorer View)

<td class=”ms-toolbar”> <table cellpadding=1 cellspacing=0 border=0> <tr> <td class=”ms-toolbar” nowrap><span class=’ms-SPLink’>  <span class=’ms-HoverCellInActive’ onmouseover=”this.className=’ms-HoverCellActive'”; onmouseout=”this.className=’ms-HoverCellInActive'”>      <a style=’cursor:hand’ title=”tooltip text” tabindex=”0″ accesskey=”\” id=”CustomMenuLink” onkeydown=”MSOMenu_KeyboardClick(this, 13, 40)” onclick=”MSOWebPartPage_OpenMenu(MSOMenu_CustomMenu, this);”>New Document <img align=”absbottom” src=”/_layouts/images/menudark.gif” alt=”tooltip text” /></a>  </span></span><span>   <menu id=”MSOMenu_CustomMenu” class=”ms-SrvMenuUI”>        <ie:menuitem onMenuClick=”javascript:]]></HTML><GetVar Name=”WPQ”/><HTML><![CDATA[createNewDocumentCustom(‘]]></HTML><ListUrlDir/><HTML><![CDATA[/Forms/BusinessCase.doc’, ‘]]></HTML><ListUrlDir/><HTML><![CDATA[‘)” type=”option”><img src=”/_layouts/images/icdoc.gif” ID=”tbbutton1N” alt=]]></HTML><HTML>”New Business Case”</HTML><HTML><![CDATA[ border=0 width=16 height=16> Business Case</ie:menuitem>        <ie:menuitem onMenuClick=”javascript:]]></HTML><GetVar Name=”WPQ”/><HTML><![CDATA[createNewDocumentCustom(‘]]></HTML><ListUrlDir/><HTML><![CDATA[/Forms/CommunicationPlan.doc’, ‘]]></HTML><ListUrlDir/><HTML><![CDATA[‘)” type=”option”><img src=”/_layouts/images/icdoc.gif” ID=”tbbutton1N” alt=]]></HTML><HTML>”New Communication Plan”</HTML><HTML><![CDATA[ border=0 width=16 height=16> Communication Plan</ie:menuitem>        <ie:menuitem onMenuClick=”javascript:]]></HTML><GetVar Name=”WPQ”/><HTML><![CDATA[createNewDocumentCustom(‘]]></HTML><ListUrlDir/><HTML><![CDATA[/Forms/EndProjectReport.doc’, ‘]]></HTML><ListUrlDir/><HTML><![CDATA[‘)” type=”option”><img src=”/_layouts/images/icdoc.gif” ID=”tbbutton1N” alt=]]></HTML><HTML>”New End Project Report”</HTML><HTML><![CDATA[ border=0 width=16 height=16> End Project Report</ie:menuitem>        <ie:menuitem onMenuClick=”javascript:]]></HTML><GetVar Name=”WPQ”/><HTML><![CDATA[createNewDocumentCustom(‘]]></HTML><ListUrlDir/><HTML><![CDATA[/Forms/ProjectInitiation.doc’, ‘]]></HTML><ListUrlDir/><HTML><![CDATA[‘)” type=”option”><img src=”/_layouts/images/icdoc.gif” ID=”tbbutton1N” alt=]]></HTML><HTML>”New Project Initiation Document”</HTML><HTML><![CDATA[ border=0 width=16 height=16> Project Initiation Document</ie:menuitem>        <ie:menuitem type=”separator” />        <ie:menuitem type=”label”>Blank Documents</ie:menuitem>        <ie:menuitem onMenuClick=”javascript:]]></HTML><GetVar Name=”WPQ”/><HTML><![CDATA[createNewDocumentCustom(‘]]></HTML><ListUrlDir/><HTML><![CDATA[/Forms/template.doc’, ‘]]></HTML><ListUrlDir/><HTML><![CDATA[‘)” type=”option”><img src=”/_layouts/images/icdoc.gif” ID=”tbbutton1N” alt=]]></HTML><HTML>”New Blank Word Document”</HTML><HTML><![CDATA[ border=0 width=16 height=16> Blank Word Document</ie:menuitem>   </menu></span>  </td> </tr></table></td>

1.5. Add Project Document Library List Definition to Site Definition

  • Change ONET.XML
    • Change the Name in the Project Element to Project Web Site
    • Add the following list definition:

<ListTemplate Name=”doclibproject” DisplayName=”Project Management Document Library” Type=”1051″ BaseType=”1″ OnQuickLaunch=”TRUE” SecurityBits=”11″ Description=”Create a document library when you have a collection of documents or other files that you want to share. Document libraries support features such as sub-folders, file versioning, and check-in/check-out.  This project management version includes multiple prince 2 templates.” Image=”/_layouts/images/itdl.gif” DocumentTemplate=”1099″></ListTemplate> 

    • Add the following DocumentTemplate item

<DocumentTemplate  DisplayName=”Project Document Templates” Type=”1099″ Description=”A Collection of Templates for Project Manangement.”>  <DocumentTemplateFiles>      <DocumentTemplateFile Name=”doctemp\word\wdtmpl.doc” TargetName=”Forms/template.doc” Default=”TRUE”/>      <DocumentTemplateFile Name=”doctemp\word\BusinessCase.doc” TargetName=”Forms/BusinessCase.doc”/>      <DocumentTemplateFile Name=”doctemp\word\CommunicationPlan.doc” TargetName=”Forms/CommunicationPlan.doc” />      <DocumentTemplateFile Name=”doctemp\word\EndProjectReport.doc” TargetName=”Forms/EndProjectReport.doc” />      <DocumentTemplateFile Name=”doctemp\word\ProjectInitiationDocument.doc” TargetName=”Forms/ProjectInitiationDocument.doc” />  </DocumentTemplateFiles></DocumentTemplate>

Published by

Mark Stokes

I am a SharePoint Server MVP and the founding Director of Red Plane, a Microsoft Silver Partner in the North West of the UK. I am interested in Travel, Extreme Sports, Photography, Technology, Gadgets, Raspberry Pi and, of course, SharePoint! Note: This is my personal blog and entries may not represent the views of my employer.

Leave a Reply

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