Tuesday, February 2, 2016

SharePoint 2013 TIP: how to create a no-code document upload hyper-link

This TIP shows you how to create a document upload hyperlink on any page in the web (i.e., website) and without having to write any JavaScript.  It uses the existing document library's Upload.aspx page, and the page will be opened as a standard page and not as a modal popup (as would normally be the case).  This method builds upon and simplifies a method developed by Jenny Hersko originally for SharePoint 2010.

Procedure

  1. Create the document library that you want to use.  Any document library will do.
  2. On any web part or wiki page, insert the App for this document library.  The App will have the same name as the document library.  By default, this App will be inserted onto the web page with Toolbar Type set to Full Toolbar.
  3. Hover the cursor over the "+ new document" hyperlink on this App.  Note the URL.
  4. Right-click on this hyperlink and choose Copy shortcut (in IE).
  5. Paste this into NotePad.  Note its structure:
    [your site URL]/_layouts/15/Upload.aspx?List={[List GUID]}&RootFolder=
    Upload.aspx is the default form created automatically for every document library.  By itself, this is all you need, and you can copy and insert this as a hyperlink.  However, after executing the upload, the user's browser is navigated to the item itself.  If you don't want this behavior but want the user's browser to be navigated back to its origin (i.e., the page that had the hyperlink), you need to the Source parameter.
  6. Build the Source parameter by replacing special characters with their appropriate ASCII code. Thus, if the page URL was "http://MyFarmUrl.com/MySite/MyPage.aspx, you would encode this as:
    http%3A%2F%2FMyFarmUrl.com%2FMySite%2FMyPage.aspx
    and the hyperlink becomes
    [your site URL]/_layouts/15/Upload.aspx?Source=
    http%3A%2F%2FMyFarmUrl.com%2FMySite%2FMyPage.aspx&List={[List GUID]}&RootFolder=
  7. Now just create a new hyperlink and set HREF= to this text.

References

  • You can easily implement your own, custom uploading form: if this custom form is saved in the same web folder as the default forms, just replace Upload.aspx with the name of your custom form and you're set to go.
  • A similar approach works for adding a new list item hyperlink to a page.  Insert the app for this list onto any page.  Right-click on the "+ new item" hyperlink on this App, and then select Copy shortcut.  In this shortcut, not that now the page is listform.aspx.  

No comments: