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:
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:
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”
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"> <A onclick="XXXX;return false;" href="#">Create new Mod Prop</A>
<IMG alt="" src="/_layouts/images/rect.gif"> <A onclick="createNewDocumentWithProgID('http:u002fu002fvm-moss2007u002fMod Propsu002fFormsu002fMod Propsu002fModPropTemplate.xlsx', 'http:u002fu002fvm-moss2007u002fMod Props', 'SharePoint.OpenDocuments', false);return false;" href="#">Create new Mod Prop</A>
19 thoughts on “Add a 'Create New Document' link to a page”
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.
I have used the code from this and surfaced buttons and links throughout a site – not just above the library….. pretty cool 🙂
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.
Very nice!! :O)
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.
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:
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.
Hmm, no, I’ve not tried this in SharePoint 2010 yet.
I like to find out how to do this in SP2010 as well. Thanks.
Hi Andy, How can I do this in SP 2010? Do I need SP Designer to do this?
Awesome…this was a great tip!
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…
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…
Thanks for the article. But unfortunately I could not find the function that you said we need to search in the code. I resolved mine from the link http://support.microsoft.com/kb/2639050
Its quite simple.
I was able to make it work for SharePoint 2010. This is what I used:
[Problem posting Code]
Thanks to Srini Sistla’s blog which I used as a guideline. Here is the link http://www.srinisistla.com/blog/Lists/Posts/Post.aspx?ID=214
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.
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.
It seem to mess with the code:
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!
@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!