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:\u002f\u002fvm-moss2007\u002fMod Props\u002fForms\u002fMod Props\u002fModPropTemplate.xlsx', 'http:\u002f\u002fvm-moss2007\u002fMod 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:\u002f\u002fvm-moss2007\u002fMod Props\u002fForms\u002fMod Props\u002fModPropTemplate.xlsx', 'http:\u002f\u002fvm-moss2007\u002fMod 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!

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

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

  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.

  3. I’ve got a web part written to do this, and will release it soon. I’ve just got the CAS policy to write and check.

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

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

  6. 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…

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

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

  9. Here’s how I did it for SP 2010:
    XXXX = website
     Create new Inventory Document

    I changed the one true to False so that it would open in Edit mode. We’re running this from an Android Tablet (Xoom with ICS) and it works great!!

    Thanks for sharing this.

  10. It seem to mess with the code:

    <div style="text-align: center"> <a class="ms-rteFontSize-5" onclick="CoreInvoke('createNewDocumentWithRedirect2',event,'http:\u002f\u002fXXXX\u002fWHInventory\u002fForms\u002ftemplate.xlsx', 'http:\u002f\u002fXXXX\u002fWHInventory', 'SharePoint.OpenDocuments', false, 'http://XXXX/_layouts/xlviewer.aspx?new=1', false, 1);return false;" href="#">Create new Inventory Document</a></div>
    
    
  11. 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!

  12. @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!

Comments are closed.