Add an ‘Add Document’ link to a page in SharePoint 2010

So recently a customer had an issue where whenever a user attempted to Upload a document, complete some MetaData fields and click ‘Save’ or ‘Check In’, instead of the form closing and the document being added to the library the browser attempted to Open the document and left them in the form, rather than redirecting them back to the library.

Here is an example of what I mean.  When using either the ‘Upload Document’ button in the ribbon, or using the ‘Add Document’ link that sits just under the library everything works fine as per the following screenshots:


However, sometimes these methods are hidden from the users and the designers do not like these default options with their branding and want to provide their own link/button to for the users.  The temptation is to simply copy the shortcut link from the already existing Add Document link, and use this as the Upload link in their button.  Here is what it looks like:{200A4026-917B-44D1-89BC-D6E49D5EE215}&RootFolder=

I have used this in my example and the text HERE has this link.  When I attempt to add a document this way I will not get the same result as you can see from the following screenshot when I attempt to add another document by clicking this:


In this case instead of uploading and redirecting  me back to the library, I am left on the form and the document is downloaded for opening in the Word Client.  Not what I want to happen.  The reason for this is that there is some Javascript that is in use with the default SharePoint Upload button and Add Document links that is not carried across when you simply attempt to use the link directly to the Upload Document form.

The workaround

To avoid this behaviour and still provide your own link/button we need to do the following.  On the page where the library is right click in your browser and view the source code of the page.  You are looking for the following lines of code:

<a class=”ms-addnew” id=”idHomePageNewDocument” href=”{200A4026-917B-44D1-89BC-D6E49D5EE215}&amp;RootFolder=” onclick=”javascript:NewItem2(event, &quot;{200A4026-917B-44D1-89BC-D6E49D5EE215}&amp;RootFolder=&quot;);javascript:return false;” target=”_self”>Add document</a>


The easiest way to locate this is to CTRL F and look for <a class=”ms-addnew” id=”idHomePageNewDocument”

Copy the equivalent code from your source into a new blank text file called “UploadDocument.txt” (or whatever you want) and save this file to your desktop.  Upload this file into SharePoint (location is not important, I put mine in the Site Assets library).

Next Add a Content Editor Web part to the page, edit the Web Part and in the Web Part options add a Content Link that points to this text file.


When you now click on the link the document will be uploaded successfully.

Mohanned Khodor

That was helpful. thanks a lot

One Shop Mall is the place whereby you directly buy goods or services from a seller in real-time online from a list of stores on our site. You deal direct with the merchant for which we provide the store links.