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!

7 comments

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

7 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.

Leave a reply

Subscribe without commenting