Changing the New document button to a drop down list in a document library


There have been many times when a customer has asked if it is possible to have a choice of doucment templates to choose from in a WSS doucment library.

There is a little bit of customisation to do this ... but it is possible. 


To do this you need to modify the schema.xml file for the DOCLIB list in the WSS site definition.  Please note that as always ... you should create your own site definition ... and not modify any of the existing ones. (See http://support.microsoft.com/Default.aspx?id=898631 for more info on this).

So here is what i did to get a drop down where you can pick which template you would like to base your new file on. 


Here is a screen shot of what the results look like:



 
To do this you need to dig into the Schema.xml file of the DOCLIB list template in your site definition.  Here is the path to the schema file i modified:


C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\1033\TEST\LISTS\DOCLIB

Jump to line 714 of an unmodified doucment library schema file ... and you should see something like the lines below:


<HTML><![CDATA[
     <td class="ms-toolbar"> <table cellpadding=1 cellspacing=0 border=0> <tr> <td class="ms-toolbar" nowrap> <a tabindex=2 ID=diidNewItem class="ms-toolbar" ACCESSKEY=N href="javascript:]]></HTML><GetVar Name="WPQ"/><HTML><![CDATA[createNewDocument();" title=]]></HTML><HTML>"New"</HTML><HTML><![CDATA[><img src="/_layouts/images/newdoc.gif" ID="tbbutton1N" alt=]]></HTML><HTML>"New"</HTML><HTML><![CDATA[ border=0 width=16 height=16></a></td> <td nowrap> <a tabindex=2 class="ms-toolbar" ACCESSKEY=N ID=diidNewItem href="javascript:]]></HTML><GetVar Name="WPQ"/><HTML><![CDATA[createNewDocument();">]]></HTML> <HTML>New Document</HTML> <HTML><![CDATA[</a></td> </tr></table></td>
    <TD class=ms-separator>|</TD>

The code above writes out the 'New' button in the document library toolbar.  This is the bit we need to replace to write out a drop down list.

Replace the above code with this below:

<HTML><![CDATA[<td class="ms-toolbar"> <table cellpadding=1 cellspacing=0 border=0> <tr> <td class="ms-toolbar" nowrap> <a tabindex=2 ID=diidNewItem class="ms-toolbar" ACCESSKEY=N href="javascript:]]></HTML><GetVar Name="WPQ"/><HTML><![CDATA[createNewDocument();" title=]]></HTML><HTML>"New"</HTML><HTML><![CDATA[><img src="/_layouts/images/newdoc.gif" ID="tbbutton1N" alt=]]></HTML><HTML>"New"</HTML><HTML><![CDATA[ border=0 width=16 height=16></a></td> <td nowrap>
     <SELECT id="]]></HTML><GetVar Name="WPQ"/><HTML><![CDATA[Select1" name="Select1" onchange="javascript:]]></HTML><GetVar Name="WPQ"/><HTML><![CDATA[createNewDocumentType(this.value);">
   <OPTION selected></OPTION>
   <OPTION value="http://server:8082/sites/Test7/Templates/Posting.dot">Report</OPTION>
   <OPTION value="http://server:8082/sites/Test7/Templates/Posting.dot">Agenda</OPTION>
   <OPTION value="http://server:8082/sites/Test7/Templates/Posting.dot">Plan</OPTION>
   <OPTION value="http://server:8082/sites/Test7/Templates/Posting.dot">Status Report</OPTION>
  </SELECT>
     </td> </tr></table></td>
    <TD class=ms-separator>|</TD>

 This inserts a dropdown list where the ‘New’ text used to be.  You can change the urls for the different templates in the <option> tags to suit your needs.  In this example they are .dot files in a document library on the same site.  However,  these could be anywhere … for example on a central site that manages all the templates for an organisation.

The dropdown box above calls a new javascript function called createNewDocumentType when an option is selected.  This still needs to be added to the schema.xml file.
Find the following code:

<HTML><![CDATA[
function ]]></HTML><GetVar Name="WPQ"/><HTML><![CDATA[createNewDocument()

This should be on line 615 of an unmodified document library schema.xml file.

Directly above these lines of code insert the following code:

<HTML><![CDATA[
function ]]></HTML><GetVar Name="WPQ"/><HTML><![CDATA[createNewDocumentType(templateUrl)


 var strSaveLocation = ]]></HTML>
    <ScriptQuote>
     <Switch>
      <Expr><GetVar Name="RootFolder"/></Expr>
      <Case Value="">
       <ListUrlDir ForInstance="TRUE"/>
      </Case>
      <Default>
       <GetVar Name="RootFolder"/>
      </Default>
     </Switch>
    </ScriptQuote><HTML><![CDATA[;
    var strProgID = ]]></HTML>
    <ScriptQuote>
     <MapToControl><HTML>|</HTML><GetFileExtension><ListProperty Default=".doc" Select="TemplateUrl"/></GetFileExtension></MapToControl>
    </ScriptQuote><HTML><![CDATA[;
    createNewDocumentWithProgID(templateUrl, makeAbsUrl(strSaveLocation), strProgID, false);
}
]]></HTML>

This is the javascript function that is called when an item in the drop down menu is selected.  It is based off the createNewDocument function that ships in the schema.xml file for a standard DOCLIB list template.

Next open a command prompt ... and do an iisrest.

Create a site based on your new site definition ... and create a doucment library.

If you have done everything right ... you should have a drop down that allows you to choose a template to base a new doucment on.


Hope you find this handy.


Comments (2)
  1. Gunnar says:

    Hi

    I have been trying this extended use of form libraries but I don’t seem to be able to make it work with Infopath forms. Any ideas?

    thanks, gunnar

  2. Muhammad Awais says:

    Hi,

    Can u tell me, How could I change the Drop-Down Menu, when we click on a File in Doc Library?

    I want to Remove "View Properties" option from it. Any Idea or reading Material?

    Thanks.

Comments are closed.

Skip to main content