Tech Tips, News and Tribal Knowledge

All the news that fits!

Linking to File Shares from SharePoint Document Libraries

Ever wished you could link directly from a SharePoint document library to a file or file share?   Well here is a code snippet  that allows you to specify the file:// prefix as well as http:// or https://.  It accomplishes this by altering the input checking on the newlink.aspx found in your layouts directory.

While you can always use the page viewer web part to accomplish the same thing, this method will allow you to mix SharePoint documents and file server documents in the same library.

This method does require that you edit one of your layout files in the ”…\12\TEMPLATE\LAYOUTS” directory, so make sure you back it up before you begin. 

1) Add the content type “Link to a Document” to your document library. If the content type doesn’t exist, simply create it with Document as the parent.

2) Navigate to your “layouts” folder and edit the newlink.aspx. Add the following at the end of the script section near the top of the page:

function HasValidUrlPrefix_Override(url)
{
var urlLower=url.toLowerCase();
if (-1==urlLower.search(“^http://”) &&
-1==urlLower.search(“^https://”) && -1==urlLower.search(“^file://”))
return false;
return true;
}

3) Find each occurance of the function HasValidUrlPrefix and replace it with HasValidUrlPrefix_Override.  It’s in there twice.

4) Save and restart IIS.

Now not only can you add a link to an http:// or https:// page, the override function allows you to link to docs on a file share. Use a syntax of:  file://\\fileserver\filename.doc.

If you’d rather have it open a folder instead, create a shortcut to the folder in question and create your link like this:  file://\\fileserver\shortcutname.lnk

If you really want to get fancy, you can edit the wss.resx file at:  c:\Inetpub\wwwroot\wss\VirtualDirectories\<app name>\App_GlobalResources

Find the section named ‘<data name=”newlink_badurl”>’ and change the value to read:  <value>Enter a valid document name and URL.  Valid URLs must begin with ‘http:’,  ’https:’,  or ‘file:’</value>

Remember to backup your layouts folder and wss.resx file before messing around in there!

16 comments

1 Star2 Stars3 Stars4 Stars5 Stars (7 votes, average: 3.71 out of 5)
Loading ... Loading ...

16 Comments so far

  1. Michael April 24th, 2009 12:02 am

    Thank for sharing.

    I’ve a question we have a document filer with tons of documents. Does this make it possible to make sharepoint index the files on the server without sharepoint importing all the content of the word documents into the sharepoint library in the SQL Server database.

    So that we could point Sharepoint to find the files in the folders on a document file server.

    thanks in advance

    Michael

  2. Craig Shrimpton April 27th, 2009 2:00 pm

    That would be nice, but unfortunately it doesn’t have that capability as the gatherer will not follow an external link unless it’s defined as a content source in the shared service provider.

  3. Lina July 20th, 2009 3:54 am

    How can I change the target in newlink.aspx to open the page in new browser?

  4. april February 3rd, 2010 6:21 pm

    This code is helpful for adding UNC paths as a link. However, you have to click on the link in URL column to open the file share location. Clicking on the name of link tries to open the link in the browser, hence it fails to open the file share location. Do you have any suggestions for opening the file share from the Name column?

  5. Linda February 22nd, 2010 4:09 pm

    Do you know of any good way to enter in the UNC path to a FOLDER not document?

    The creating a Shortcut to the folder is not an option for us. There must be some way for it to accept a folder since when you add this same exact content type to a LIST and enter a UNC to a folder it opens it fine.

  6. Linda February 22nd, 2010 5:20 pm

    Nevermind, I just figured it out. If you create your own Custom Content Type then it will open Folders properly. It just won’t open folders properly using the built in Link to Document content type.

  7. Linda Chapman March 2nd, 2010 4:07 pm

    April, if you enter only the document name in the name field it will open the document.

    So even though the Name field will show _____.aspx if you type just the document name there but not the entire path it will open it up from the Name field.

  8. DZ March 10th, 2010 10:35 am

    Possibly unrelated, but what the heck.

    Is there a way to have a file (e.g. excel) on SP be updated from another SP excel file, but only certain cells/rows/columns?

    Thanks!

  9. greg March 23rd, 2010 9:46 am

    could you show me how to open a document that is on a file share by clicking on the name column? based on your solution, I can only open the document by clicking on URL column.

  10. Linda Chapman March 26th, 2010 9:38 am

    Greg: You have to make sure and only enter the name of the document in the Name field, do not include the extension. So if your document name is MyDoc.doc you need to enter:

    Name = MyDoc
    URL = file://Servname/ShareName/FolderName/MyDoc.doc

  11. John April 27th, 2010 10:22 am

    Great ideas here. I have been searching for days as a new user for how to link to documents on our internal server. THIS WORKS. No programming, just cut and paste and it works.

    THANK YOU

  12. praneeth July 8th, 2010 11:57 am

    Now I have created a dashboard on the team site and created few buttons. How can i link the files in the internal file server to the buttons on the teamsite dashboard.

  13. manish July 10th, 2010 5:27 pm

    Excellent I have been trying to find a simple way to accomplish this. I need to test it out when I get back to the office on Monday, just have Mac’s laying around my house.

  14. Philippe July 28th, 2010 11:41 am

    @Linda: I haven’t succeeded in making a shared FOLDER accessible by clicking the name. Documents on the share work fine. So does clicking the folder’s URL column. But the folder name column doesn’t work. I’ve followed the steps from your windows live page pretty closely (I’ve created a custom content type as described there), but instead of modifying the NewLink.aspx core file, I have created a copy containing the modified validation function, and specified it as the content type’s document template (within the ‘Advanced Settigs’). Shouldn’t that do the trick too?

  15. Linda Chapman July 29th, 2010 7:40 am

    @Philippe: To make the Folder linkable you have to do 2 things. 1)You MUST create your own URL Content Type by copying from the exising built in content type, and 2) you must enter the folder name only in the Name field.

    I always modify the NewLink page directly I don’t refer to a copy, so not sure about that. You followed the instructions at http://LindaChapman.BlogSpot.com right?

    If you are able to make the hyperlink but you can’t click on it from the Name field then that means usually what you entered in the Name field is wrong. Enter the complete file UNC for the URL field but only the name of the folder in the Name field. Feel free to email me pictures at LindaChapman @ Live . com

  16. Angela August 12th, 2010 12:55 pm

    Does this method require server access? Using SharePoint Designer, I do not seem to have access to a ”…\12\TEMPLATE\LAYOUTS” directory. I am an end user with full control and site ownership, but do not have access to the server. Is there any solution for me to accomplish adding links to file shares in a document library?

Leave a reply

Subscribe without commenting