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”
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"> <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"> <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!


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