Creating a Link to Open a Word Document Content Type in SharePoint 2010

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.


This ends up with some JavaScript that runs CoreInvoke that then appears to wrap createNewDocumentWithRedirect.  Trying to read through all the encoded gibberish will make your head hurt, but you can do it and it will work. 

My goal was to make this as simple as possible and, assuming it was going to require some JavaScript to make it happen, I wanted it to be a lot more readable.  Also, I don’t want to include a lot of extra, hard-to-read and understand, code that doesn’t really add to the solution.  In this vein, I felt I should be able to execute createNewDocumentWithRedirect and not have to wrap it in anything else.  Perhaps I don’t understand fully what CoreInvoke is doing.  What I’ve found is it doesn’t appear to be doing much for the solution I need.

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."




So, if we continue on and create an anchor <a> link with some JavaScript on the onclick event, it looks something like this, which is much easier to read.

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&#8217;, 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.





1 Response to “Creating a Link to Open a Word Document Content Type in SharePoint 2010”

  1. 1 Sajche
    February 14, 2014 at 12:40 pm

    VERY helpful !! this is what i was looking for.
    I will try your solution!
    many thanks!!!

Leave a Reply

Fill in your details below or click an icon to log in:

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 )

Connecting to %s

Asif Rehmani’s SharePoint Videos


Click to access a wealth of SharePoint videos

SharePoint Rx

SharePoint Rx Home


Posts by Date

January 2014
Support Wikipedia

%d bloggers like this: