Just little about C#, .NET, SQL Server, SharePoint and SAP

Adding a document type in New Document drop down

Posted by zieglers on October 6, 2010

Have you ever tried to add an extra document template to New button in a SharePoint library, and realized that you can’t do this unless you add another content type to that library?

In other words, you want your users to be able to create more than one document type in a library, but you don’t want to use multiple content types on that library.

Here is a way how you can do it…

Trick is using javascript in UrlAction. But specifically there is one function you have to use, which is createNewDocumentWithProgID.

In this example, i’ll show you how to add, say create Excel sheet button, in addition to Word.

1. Specify a location for your document template. For instance, {SiteUrl}/_layouts/DocTemplates/Book.xls

Put your document templates in that location, or in your feature make sure that your document templates are provisioned to that location.

2. Create a feature for your new CustomAction, which will host our javascript in its UrlAction. Use following CustomAction code in your elements.xml.


<?xml version=”1.0″ encoding=”utf-8″ ?>
    Title=”Create New Document Drop Down”
    Description=”Adds document types to the New Document dropdown menu.”
    <ElementManifest Location=”elements.xml” />


<?xml version=”1.0″ encoding=”utf-8″ ?>
<Elements xmlns=http://schemas.microsoft.com/sharepoint/ >
  <!– Document Library Toolbar New Menu Excel –>
  <CustomAction Id=”DocLibNewToolbar”
    Rights =”AddListItems”
    Description=”Creates a new Microsoft Excel Document”
    Title=”Microsoft Excel Document”>
    <UrlAction Url=”…JavaScript goes here…“/>
</Elements >

3. Put below script in url attribute of UrlAction.



var templateurl = GetTemplateName();

function GetTemplateName()
 var templatename ='{SiteUrl}/_layouts/DocTemplates/Book.xls’;
 return templatename ;

var libraryurl = getLibraryName();

function getLibraryName()
 var URL = window.location.toString();
 var lname = URL.split(‘/’);
 var forms = 0;
 var viewname = lname[lname.length-1];

 if (lname[lname.length-2] == ‘Forms’)
  forms = lname[lname.length-2].length;
 var Lurl = URL;
 Lurl = Lurl.substr(0,Lurl.length-viewname.length-forms-1);
 return Lurl;

createNewDocumentWithProgID(templateurl, makeAbsUrl(libraryurl),’SharePoint.OpenDocuments’, false);



Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: