You might be familiar with creating a content type on a document library and associating a Word template with that content type. When you do this, you end up with a very nice link in the Documents menu that fills in the blank, "I want to create a new ______." In this case, I want to create a new ECCN Classification Document.
When Word opens up, it uses the template on the list content type so you can expose the content type columns as Quick Parts in Word. If you’re not familiar with this process, it’s kind of a poor man’s form for SharePoint.
Once you’ve done this, you might want to create a link to use this on other pages and in other places…and least that’s what I wanted to do.
When you start looking around for a solution to this, you might find this post by Srini Sistla which is pretty much the route I originally went down. It involves viewing the source on the page with the menu and attempting to replicate what the menu does.
If you do a little research, you’ll find there is a pretty straightforward definition for the createNewDocumentWithRedirect function. Perhaps the most difficult part of using any function is to know what to pass for each of the parameters. Here’s where I’ll try and elaborate and make it easy for you. Here’s the definition.
function createNewDocumentWithRedirect(strTemplate, strSaveLocation, strProgID, bXMLForm, strRedirectUrl, defaultItemOpen)
strTemplate – A string value that identifies the URL to the template file associated with the content type.
strSaveLocation – A string value that identifies the default save location you want Word to display when performing a save.
strProgID – A string value to the program ID (ProgID) SharePoint.OpenDocuments which identifies a registry entry that is associated with a CLSID. Like the CLSID, the ProgID identifies a class but with less precision because it is not guaranteed to be globally unique.
bXMLForm – A boolean (true/false) indicating whether this is an XML form. False for Word and other office documents.
strRedirectUrl – A string value that contains the URL to redirect to after closing Word. NOTE: I’m not positive this works when closing Word. I haven’t been able to get it to work. Does it require CoreInvoke? I tried that and it didn’t work either.
defaultItemOpen – Specifies whether to open items in a client application or in the browser. Not really sure if it has much affect on opening Word documents in this context, but a 0 means open in the thick client and 1 means open in the thin (web) client.
Here’s what the ProgID looks like in the registry. You’ll see that SharePoint.OpenDocuments points to SharePoint.OpenDocuments5 which, in turn, points to the CLSID (unique identifier for the class). Kinda’ like "there’s a hole in the bottom of the sea."
NOTE: If you copy and paste this be aware that the single quotes can get changed to the accent grave variety (not the ambidextrous single quote we are used to, the ')
<a onclick="createNewDocumentWithRedirect(‘https://yoursite.com/sites/WPL/CCL/Saved Records/Forms/ECCN Classification Document/ECCN Classification.docx’, ‘https://yoursite.com/sites/wpl/ccl/saved records’, ‘SharePoint.OpenDocuments’, false, ‘https://yoursite.com/sites/wpl/ccl’, 1);" href="#">createNewDocumentWithRedirect Test</a>
When you put this in a content editor web part in SharePoint 2010, it will encode the apostrophes and change them to '.
However, you’ll note that I didn’t have to encode the spaces in my links, and they work just fine.
So, what are these links anyway? The first one, strTemplate, is the link to the template that was uploaded. This is the link to the template on the list. You can see this in SPD or look at the list content type page and copy it from the Edit Template link.
https://yoursite.com/sites/WPL/CCL/Saved Records/Forms/ECCN Classification Document/ECCN Classification.docx’
When you implement this in a content editor web part it looks something like this. In this case I have two test links. The "Word 2010" link uses the CoreInvoke function and the "createNewDocumentWithRedirect Test" link uses the createNewDocumentWithRedirect function. Both seem to give me the same results, but the 2nd one is much easier to read and duplicate.