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.
feature.xml
<?xml version=”1.0″ encoding=”utf-8″ ?>
<Feature
Id=”EBEEB609-5CB9-4e7d-8771-349B6060CD64″
Title=”Create New Document Drop Down”
Description=”Adds document types to the New Document dropdown menu.”
Scope=”Site”
Hidden=”FALSE”
xmlns=”http://schemas.microsoft.com/sharepoint/”
>
<ElementManifests>
<ElementManifest Location=”elements.xml” />
</ElementManifests>
</Feature>
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”
RegistrationType=”List”
RegistrationId=”101″
GroupId=”NewMenu”
Rights =”AddListItems”
Location=”Microsoft.SharePoint.StandardMenu”
Sequence=”1″
ImageUrl=”/_layouts/images/lg_icxls.gif”
Description=”Creates a new Microsoft Excel Document”
Title=”Microsoft Excel Document”>
<UrlAction Url=”…JavaScript goes here…“/>
</CustomAction>
</Elements >
3. Put below script in url attribute of UrlAction.
===============================================
Javascript:
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);
===============================================
zieglers
You must be logged in to post a comment.