Monday 25 July 2011

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>

Source: http://os.com/blog/linking-to-file-shares-from-sharepoint-document-libraries

No comments:

Post a Comment