Add a 'Create New Document' link to a page

Okay, so in SharePoint we’ve got document libraries. In them (provided we have the rights) we can go to the toolbar and click ‘New’, select a document type, and be shown a template document to start filling in. That’s pretty nice.

Often, though, we might want to surface those documents (or some of those documents) on a Page – either a Publishing Page or a Normal Page. We can do that with the ListView Web Part:

listview-with-add-new-link

As you can see, it can show an ‘Add new document’ link. We could also get it to show a toolbar very similar to the one in the List itself, or we can configure it to show nothing at all!

However, the ‘Add New Document’ link and the toolbar have quite different functionality. The ‘New’ button on the toolbar opens a new document, and lets you fill in the template, whereas the ‘Add new Document’ link simply takes you to the file upload page – so you don’t get a nice blank templated document to fill in.

That’s a little unfortunate. We’d a customer who didn’t want to show all the toolbar on their home page, but wanted to use a specific document template for when users tried to create a document. So, in short, the functionality of the toolbar menus – but in a link at the bottom of the ListView, like this:

new-create-document-link

So, how did I do this? Well, I started by turned off ‘Toolbar’ and ‘Summary toolbar’, so there was no way to add a new document with the ListView web part. Then, below it, I added a Content Editor web part and put the HTML code in there.

But how did I actually make this work? Well, I turned on the full toolbar, and then viewed the page source. I found the MenuItem itself – if you want to do this for yourself, search for “zz11_New0″ or “createNewDocumentWithProgID”

Looking in the MenuItem, I could see it was running some JavaScript when it was clicked on. I copied the Javascript it was running. For me, this was:

createNewDocumentWithProgID('http:u002fu002fvm-moss2007u002fMod Propsu002fFormsu002fMod Propsu002fModPropTemplate.xlsx', 'http:u002fu002fvm-moss2007u002fMod Props', 'SharePoint.OpenDocuments', false)

Next, I turned off the toolbar for the Mod Props web part, and I then added my new content editor web part. I switched to HTML mode, and typed in:

<IMG alt="" src=" /_layouts/images/rect.gif">&nbsp;<A onclick="XXXX;return false;" href="#">Create new Mod Prop</A>

Where XXXX is the JavaScript I copied from the toolbar. So, my full HTML looked like:

<IMG alt="" src="/_layouts/images/rect.gif">&nbsp;<A onclick="createNewDocumentWithProgID('http:u002fu002fvm-moss2007u002fMod Propsu002fFormsu002fMod Propsu002fModPropTemplate.xlsx', 'http:u002fu002fvm-moss2007u002fMod Props', 'SharePoint.OpenDocuments', false);return false;" href="#">Create new Mod Prop</A>

I save this, and set my content editor web part to have no chrome (no title or anything). Presto, done! I would point out that updating the template could mean updating the JavaScript in the content editor. Still, not a bad effort!

Add a 'Create New Document' link to a page

19 thoughts on “Add a 'Create New Document' link to a page

  1. Alana says:

    Hi Andy,

    I must say – I love your blog and I really have got some great tips from you over the past few months.

    Thought I’d just add to this by saying that my colleague, James Milne has released a content type toolbar which you may find really useful for achieving something like this in the future.

    http://www.myriadtech.com.au/blog/James/Lists/Posts/Post.aspx?ID=5

    I have used the code from this and surfaced buttons and links throughout a site – not just above the library….. pretty cool :-)

    Alana

    Like

  2. Hi Alana,

    Thanks, that is pretty neat! I’d wondered about doing something similar (i.e. actually build a proper web part), though more basic, but that was going to take longer than I had at the time.

    A useful component, though.

    Like

  3. Hi Andy,

    Thanks for this post. I needed a link to create a new document from a content type template associated with a document library, but the link was to be placed on a task panel for display in a client application (ouside of SharePoint).

    I managed to achieve this using a combination of the technique explained in your post, but added it to a function in the head section a separate page, which was called using the settimeout method. This allowed a short message to be displayed before opening a blank document from the template, then the page redirects to the document library.

    I also referenced this post in a related post of my own:

    http://blog-sharepoint.blogspot.com/2010/08/useful-tip-add-link-to-create-new.html

    Thanks

    Like

  4. Any idea how to do this in sharepoint 2010? when I try I get an error telling me that I need a sharepoint browser to open this document and to use the add new document to upload a document instead.

    Like

  5. Neha sethi says:

    I have fixed this issue by selecting Full Toolbar in Toolbar Type. The default content type attached to the form library gets opened up and it no more redirects you to uplaod a document…

    Like

  6. Hi…,

    you can achieve this by adding the following script to the page where you need to change…. you can either add using SharePoint designer or use Content editor webpart…

    document.getElementById(“testid”).innerHTML=”your new text goes here”

    Where testid is the ID of the <a> anchor tag… for which you need to change the text…

    Like

    1. Thanks navi2x5, that’s not a bad way of doing it actually. It’s a bit fiddly – it won’t update automatically if you change the template, for example (but how often does that happen), and I’m not sure how well it’d handle Alternate Access Maps – but it is pretty straight forward.

      Thanks, it’s worth knowing about.

      Like

  7. It seem to mess with the code:

    &lt;div style=&quot;text-align: center&quot;&gt; &lt;a class=&quot;ms-rteFontSize-5&quot; onclick=&quot;CoreInvoke('createNewDocumentWithRedirect2',event,'http:u002fu002fXXXXu002fWHInventoryu002fFormsu002ftemplate.xlsx', 'http:u002fu002fXXXXu002fWHInventory', 'SharePoint.OpenDocuments', false, 'http://XXXX/_layouts/xlviewer.aspx?new=1', false, 1);return false;&quot; href=&quot;#&quot;&gt;Create new Inventory Document&lt;/a&gt;&lt;/div&gt;
    
    

    Like

  8. Steve says:

    Is it possible to place a link in a word document that will open a new form template in a SharePoint document library? Thank you!

    Like

  9. Rich B says:

    @Steve – the solutions posted here are web based, and works as the link tells the browser where to pick up the template and where to save it.

    In word if you added a hyperlink like http://PATHTOLIBRARY/Forms/CONTENTTYPENAME/NAMEOFTEMPLATEFILE.xltm it would be able to open this file.

    However if you edited and saved it, it would save over the existing template.. so if you could train your users just to grab the file from there and save somewhere else, I guess that could work.. but End Users don’t always follow the master plan!

    Like

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 )

Google+ photo

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

Connecting to %s