Sunday, May 9, 2010

How to add a Link to a Document external to SharePoint

You can add links to external file shares or/and file server documents to your document library very easily. Why would you want to do this? Primarily so all your MetaData to all your documents are searchable in the same place.

First a Farm Administrator will need to modify a core file on the front end server.  Then you must create a custom Content Type. If you use the built in content type you will not be able to link to a Folder directly.
Edit the NewLink.aspx page to allow the Document Library to accept a File:// entry.
  1. Go to the Front End Web Server \12\template\layouts directory.
  2. Open the file NewLink.aspx using NotePad. If I have to tell you to take a backup of this file first then you have no business editing this file (really).
  3. Go to the end of the script section near top of page and add:
    function HasValidUrlPrefix_UNC(url)
    {
    var urlLower=url.toLowerCase();
    if (-1==urlLower.search(”^http://”) &&
    -1==urlLower.search(”^https://”) && -1==urlLower.search(”^file://”))
    return false;
    return true;
    }
  4. Use Edit Find to search for HasValidURLPrefix and replace it with HasValidURLPrefix_UNC (you should find it two times).
  5. File – Save.
  6. Open command prompt and enter IISreset /noforce.
Important: To link to Folders correctly you must create your own content type exactly as below and not use the built in URL or Link to Document at all.

Create custom Content Type
  1. Go to your Site Collection logged in as a Site Collection Administrator.
  2. Site actions – Site Settings – Modify All Site Settings.
  3. Content Types
  4. Create
  5. Name = URL or UNC
  6. Description = Use this content type to add a Link column that allows you to put a hyperlink or UNC path to external files, pages or folders. Format is File://\\ServerName\Folder , or http://
  7. Parent Content Type,
    1. Select parent content type from = Document Content Types
    2. Parent Content Type = Link to a Document
  8. Put this site content type into = Existing Group:  Company Custom
    1. image
  9. OK
  10. At the Site Content Type: URL or UNC page click on the URL hyperlink column and change it to Optional so that multiple documents being uploaded will not remain checked out.
  11. OK
    1. image
Add Custom Content Type to Document Library
  1. Go to a Document Library
  2. Settings – Library Settings
  3. Advanced Settings
  4. Allow Management Content Types = Yes
  5. OK
  6. Content Types – Add from existing site content types
  7. Select site content types from: Company Custom
  8. URL or UNC – Add – OK
  9. Click on URL or UNC hyperlink
  10. Click on Add from existing site
  11. Add all your Available Columns – OK
  12. Column Order – change the order to be consistant with the Document content type orders.
  13. Click on your Document Library breadcrumb to test.
  14. View – Modify your view to add the new URL or UNC column to your view next to your Name column.
Create Link to Document
  1. Go to the Document Library
  2. New – URL or UNC
  3. Document Name: This must equal the exact file or folder name less the extension.
    1. Example: My Resume 
    2. Example: Folder2
    3. Example: Doc1
  4. Document URL: This must be the UNC path to the folder or file.
    1. Example: http://LindaChapman.BlogSpot.com/Folder1/Folder2/My Resume.doc
    2. Example: http://LindaChapman.BlogSpot.com/Folder1/Folder2
    3. Example: File://\\ServerName\FolderName\FolderName2\Doc1.doc
You might see other blogs that say you can't connect to a folder and must create a shortcut first. They are wrong. You can by the method above.

The biggest mistakes I see are:
  1. People click on the NAME field instead of the URL field. They are not the same. You MUST click on the URL field to access the Folder properly.
  2. People use the built in Link to Document content type thinking it is the same or will save them a step. It is not the same.
  3. People type the document extension in the Name field. You can not type the extension in the name field. It will see it is a UNC path and ignore the .aspx extension.
  4. People enter their slashes the wrong direction for UNC paths.

21 comments:

  1. Very interesting and carefully written. Thank you. architekt

    ReplyDelete
  2. Hi Linda,

    Followed the steps, but when I try to link a folder, sharepoint attempts to add .aspx and it fails.

    We have a fairly large document store on a fileserver that I am attempting to access using sharepoint.

    ReplyDelete
  3. Worked like a charm. -Scott Wells, Senior Systems Administrator, Easter Seals Hawaii.

    ReplyDelete
  4. Brilliant. Thanks very much Linda. Just what I needed and easy to follow.

    ReplyDelete
  5. Thank you for this great article. I applied it and it works just fine.
    However for most users typing the correct path will be some trouble.
    Therefore I'll link the command "copy UNC-path" to the right mouse button. That way it will be only a copy paste thing.
    Is it possible to make the text in the textbox by default file:// instead of http:// ? This would be another timesaver and avoid problems for most users.
    Thanks!

    ReplyDelete
  6. Nice to see that I was able to find this post. I found it first here: http://technotes.smoothwater.net/2012/01/external-file-link-in-sharepoint-2010.html

    He was nice enough to give you a one-liner credit. He failed to mention all he did was copy the entire thing word for word.

    ReplyDelete
  7. A very rare breed of person provides a service like yours to the SharePoint community. I have used two of your suggestions "Links to File Shares" and "Vanity URL's" and both have solved some huge problems for me. Thank you again for such wonderful easy solutions to some sticky problems...

    ReplyDelete
  8. I have used two of your solutions in the past and they worked wonderfully, Vanity urls and file shares external to SharePoint. Is it possible to also connect to external FTP sites from within SharePoint? I have been Googleing for the past week and have not had any luck. Any help would be be greatly appreciated.

    Louis - SharePoint Admin, CBS News NY.

    ReplyDelete
  9. Hey Linda, I found this post to be most helpful, but I have a problem. After I've gone through all the instructions and I click on the link to test it out, it opens up [documentname].aspx like I assume it is supposed to, but it doesn't prompt me to open/save the document. Now, when I edit the properties of the link and click the "Click here to test" link, it works. This is SharePoint Foundation 2010, btw.

    ReplyDelete
    Replies
    1. I'm having the same issue with 2013. Has there been any resolution to this?

      Delete
    2. Actually, I just figured it out. The Document Library's view must be altered to add the 'URL' column. Then, when a user wants to retrieve the document, the URL column value must be click rather than the document name.

      Delete
  10. Nice clear set of straight forward instructions. Just what I am looking for. However, does this work in SP2007? Cannot find that path - neither template nor Layouts. Thanks

    ReplyDelete
  11. Hi Linda. I was able to get this to work using std settings in SP2007Sp1( ref Gilster) and it takes you to folders, not only files, on the "external-to SP" server inside the firewall. However I would like my users to be able to access those same folders from the wild. I believe Gilster indicates you should be able to, but I must have missed something. Can you help?

    ReplyDelete
  12. I am not sure where to place the code. You say "end of the script section near the top of the page." Where is that? Also, I only find 14 and 15.. no 12. Does that matter?

    ReplyDelete
  13. I do not see any answers but I will ask all the same. I followed the instructions and all appears well but when I create a new UNC and ent the path File://\\ServerName\FolderName\FolderName2\Doc1.doc Sharepoint changes it to File://\\ServerName\FolderName\FolderName2\Doc1.doc File://ServerName/folderName/FolderName2/Doc1.doc sometimes it even adds file:////path. What am I missing here?

    ReplyDelete
  14. No Luck :( i followed every steps, i am using sharepoint 2013. Getting blank screen and the page is with .aspx extension and the url is not clickable.

    Help

    ReplyDelete
  15. Thank you for this golden nugget Linda. Is there anyway in which the remote file can be retrieved in the security context of the Sharepoint service account? I would imagine so else the goal of centralizing the documents with meta-data becomes unfeasible if each SharePoint user needs to be authenticated and authorized on the remote server.

    ReplyDelete
    Replies
    1. Thank is not considered a proper security practice. SharePoint uses active directory authentication. If you wanted to create a Site Collection that allows anonymous access you could, but most don't. You could use External Sharing and create an anonymous link as well. But again, you want the authentication for the logging and audit trail.

      Delete
  16. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. The solution above only worked with version 2010, and it is based on the user having permissions to both the SharePoint site the external link is in AND the file share and file properties of the external file at the file location. It would be considered a security issue to use the SharePoint service account as that would not be following the "least privileged" model which is best practice. Also that would not work because SharePoint only shows you data the currently logged on user has, not the SharePoint service account. Again it follows least priviledged model, what you see is only what you have permissions on.

      Delete
  17. Great write up, however, have you ever seen an instance where when you click attempt to use "New Link to a Document" or "URL" as it was named here that NewLink.aspx triggers Sharepoint Designer to launch rather than a dialog to enter a URL???

    ReplyDelete