Open a document from a list and control in which document library Office/Word/Excel should default to on Save/Save As, SharePoint 2007

Often our SharePoint customers have a set of document templates that is larger than it is possible/practical to define as Content Types with document templates (and then available on the New document meny/button on a document library).

I found the createNewDocumentWithProgID javascript function (SharePoint's own) when browsing the html source of a page displaying a document list including the list toobar and the New document command.

How to use it? The following pseudocode will help you to get some ideas on how to create a solution which will set the default save to location for the Office program to the 'http://myserver/asite/Documents' library in the site where the command/action is executed:

  1. Collect and categorize all your document templates (Word, Excel, Visio, Powerpoint) in a document library
  2. Create a Custom Admin Page, e.g. createdocumentfromtemplate.aspx, and place it in the /_layouts/
  3. Display all your document templates (from the library created in 1)) in a page named createdocumentfromtemplate.aspx using some custom code, controls, or something, but make sure that the URL's href parameter contains the following (the correct paths you have to create on the fly) : javascript:createNewDocumentWithProgID('http://myserver/documenttemplates/thetemplate.docx', 'http://myserver/asite/Documents' , 'SharePoint.OpenDocuments', false);
  4. Create a button, menu or an Action that calls /_layouts/createdocumentfromtemplate.aspx

Of course a lot of details are missing, but in it should give you some ideas.

In one case I used the Content by Query web part to list a set of document (templates) from a document library, and by using the following line in my Item Style.xsl I set the default save catalog for Office application to me [current site]/documents:

<a href="javascript:createNewDocumentWithProgID('{$SafeLinkUrl}', document.URL.split('/').slice(0, document.URL.split('/').length-2).join('') + '/documents', 'SharePoint.OpenDocuments', false);" target="{$LinkTarget}"
title="{@LinkToolTip}"> <xsl:value-of select="$DisplayTitle"/> </a>

Happy coding!

No comments: