The “Link to a Document” content type in SharePoint allows you to add URL links to a Document Library, much like you would with a Links List, but in this case you can add a Link item to a document library without having to add a document.
The “Link to a Document” content type is very simple containing only a single column of type Hyperlink or Picture;
Once added to a document library, you can create a new link using the New Document menu from the ribbon, you are navigated to a layouts page called NewLink.aspx;
On here you enter the ‘Document’ link name (this is the links name or label you’ll see in list views etc) and the actual URL itself.
Click OK and your link is added to the library, notice the items ‘Link’ icon overlay.
Clicking on the ‘document’ then navigates you to the URL you entered previously.
What the ‘NewLink.aspx’ page does is create an ASPX page containing a URLRedirector control, this control then picks up the value of the ‘URL‘ column off the current item and redirects to the URL column value – pretty cool right.
When you try to add a long URL to a document link, you’ll see a validation error message;
This is a bit weird AFAIC, the ‘Document URL’ input field is restricted to 255 characters, which is correct given that a Hyperlink field is being used as backing storage, and the ‘Document Name’ field shouldn’t have any bearing on the length of the URL (255 character limit aside).
The culprit is the validation function used on the page, shown below;
For no good reason I can think of, its adding the length of the ‘Document Name’ field to the length of the ‘Document URL’ field, and if its more than 260 characters you get the error message. But these 2 elements are not related in this context and so the comparison is incorrect;
- The ‘Document Name’ value is stored in the Title/FileLeafRef column
- The ‘Document URL’ value is stored in the ‘URL’ columns
Personally, I think this code is more relevant when creating Folders, where the folder name has a direct bearing on the items final SharePoint URL.
You could modify the NewLink.aspx file in the 15 hive.
I’m being rhetorical of course, you wouldn’t really want to do that.
In the code above, I check that the ‘Document Name’ field value is less than 128 characters and the ‘Document URL’ field value is less than 255 character, of course before running that code you should check that the NewLink.aspx page is loaded.
A final version may look something like this;