Link to Network File Share Documents in SP Doc Libraries
This is a neat solution to a limitation of SharePoint document libraries. OOTB SharePoint document libraries do not support linking to files in network file shares. It does however support linking to documents stored in other document libraries, via the “Link to Document” content type. The solution builds on this mechanism.
The problem with the OOTB “Link to Document” content type is that it validates that the link points to a document stored in SharePoint on creation. The way the content type works is that it redirects the user to an application page called “NewLink.aspx”, which is stored in the _Layouts directory. The application page builds an .aspx page dynamically, which is stored in the SharePoint Document Library. The newly created page contains the code to redirect the user to the document referenced in the URL field of the content type.
As modifying the NewLink.aspx page is NOT supported by MS, as any updates to SharePoint may overwrite the changes. The solution to this is to create a copy of the NewLink.aspx page in a custom directory in the _Layouts directory. The validation code is modified in the new file as follows:
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;
}
A copy of the “Link to Document” Content type is created and the definition is modified as follows:
<ContentType ID=”
0x01010A00B891CB0B16E1174F9DFEF504DDF2B3FE”
Name=”Link to Network Share Document”
Group=”CUSTOM GROUP”
Description=”Links to document stored on Network share using a UNC address”
Version=”0″>
<FieldRefs>
<RemoveFieldRef ID=”{fa564e0f-0c70-4ab9-b863-0177e6ddd247}” Name=”Title” />
<FieldRef ID=”{c29e077d-f466-4d8e-8bbe-72b66c5f205c}” Name=”URL” Required=”TRUE”/> <!– URL –>
</FieldRefs>
<DocumentTemplate TargetName=”/_layouts/CUSTOM_DIR/NewLink.aspx” />
</ContentType>
The new application and content type can then be packages into a feature and deployed as a solution. The feature can then be activated on the sites where it is required.
Notes
- The newly created content type should be based off the OOTB “link to Document” Content Type. i.e. the new content type ID should start with 0x01010A;
- This solution does not check for permissions on the Network file share. The ACL of the file will dictate the permissions. If the user does not have permissions an error message will be displayed;
- Standard SharePoint Document library security will be honoured. If the user does not have permissions to the list item they will not see the link to the network file share;
- UNC address should have the flowing format: file://[filepath]/[fileName].[extension]. There is no validation of the UNC address format;
- This method does not provide any browse to functionality for the end user. They will need to be trained on how to locate the correct UNC address.