Saturday, January 19, 2013

Display “Upload Document” button on any web part page

So my client got a little too fancy about having a way to upload documents from anywhere on “a site”, to a particular document library available within that site.

Referring to the SharePoint way of uploading documents as below, I was made to run for a solution that would allow them to add this functionality to any web part page.

image

This wasn’t that bad of a thought. Well, at the end it got out to be quite straight forward, if you are happy and comfortable with java-script.

This is what was done, to allow them quickly add a script in a content editor and display a huge button like this:

image

Now the code:

<div class="ms-uploadbtnlink">
  <button onclick="javascript:OpenNewFormUrl(&#39;Documents/Forms/upload.aspx&#39;);return false;" type="submit">
    <nobr>
     <img alt="Upload Document" src="/_layouts/Images/uploaddoc.png"/>&#160;<span>Upload Document</span>
    </nobr>
  </button>
</div>

Thanks for reading!