Adding a link to a shared folder in document library using "Link to Document" content type
Recently I was asked by one of my customers to help them with a solution to allow uses adding link to documents on their shared folder, OOB "Link To Document" contnet type can be used to add a link in document library refrencing documet in another document library, if user tries to add a URL with differnet schema (e.g. FTP, File) the form simply does not let the link to be added.
Solution
- Create a custom aspx page based on "NewLink.aspx" under 12 hive\Template\Layouts folder and call is "NewSharedFolderLink.aspx"
- In "NewSharedFolderLink.aspx" modify ValidateInput() and TestDir() as follows:
function ValidateInput()
{
var form = document.forms.<%SPHttpUtility.NoEncode(Form.ClientID,Response.Output);%>;
var folderUrl = form.<%SPHttpUtility.NoEncode(UrlInput.ClientID,Response.Output);%>.value;
var name = form.<%SPHttpUtility.NoEncode(NameInput.ClientID,Response.Output);%>.value;
if (name == null ||
folderUrl == null ||
typeof(name) == "undefined" ||
typeof(folderUrl) == "undefined" ||
name.length == 0)
{
alert(L_EnterValidUrl_Text);
return false;
}
if (name.length > 128 ||
name.length + folderUrl.length > 260)
{
alert(L_ItemOrFolderNameTooLong);
return false;
}
return true;
}
function TestDir()
{
var form = document.forms.<%SPHttpUtility.NoEncode(Form.ClientID,Response.Output);%>;
var folderUrl = form.<%SPHttpUtility.NoEncode(UrlInput.ClientID,Response.Output);%>.value;
if (folderUrl == null ||
typeof(folderUrl) == "undefined" )
{
alert(L_EnterValidUrl_Text);
return;
}
try
{
var form = document.forms.<%SPHttpUtility.NoEncode(Form.ClientID,Response.Output);%>;
window.open(form.<%SPHttpUtility.NoEncode(UrlInput.ClientID,Response.Output);%>.value,'_blank');
}
catch(e)
{
alert(L_EnterValidUrl_Text);
}
}
- Create a custom content type based on "LinkToDocument" content type:
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ContentType ID="0x01010A00E1834F80FD414751B021043FCC088B74" Name="SharedFolderLink" Group="$Resources:Document_Content_Types" Description="Shared Folder Link" Version="0">
<DocumentTemplate TargetName="/_layouts/NewSharedFolderLink.aspx" />
</ContentType>
</Elements>
- Package everything as a feature install and activate it on your site
- In document library add the "SharedFolderLink" content type
Update: A sample solution package can also be downloaded from here to install the custom content type.