8/09/2007

SharePoint: Adding hyperlinks to document libraries

Sometimes you have external content that you would like to make available from your document library without uploading a file. Examples include documents in other SharePoint sites or libraries, and even links to other web pages including SharePoint pages and external web sites.

Turns out SharePoint already has this built-in, just well hidden. There is a built-in Content Type called "Link to a Document". Just add this to your library and then just click the "New" dropdown and select "Link to a Document"! It will simply ask you for a document name and url. You can supply a URL to anything that starts with "http://", including both SharePoint documents and external web pages. It does not support a link to a network share such as "\\myfileserver\folder1\somedoc.doc".

  1. Display your library (Example: Shared Documents)
  2. Click Settings and Library Settings
  3. Click Advanced Settings
  4. Check "Allow management of content types" and then OK
  5. In the Settings page scroll down to Content Types and click "Add from existing site content types"
  6. Select "Link to a Document", click Add and then Click OK
  7. Go back to your library and click the New dropdown and select "Link to a Document"
  8. Enter a display name (Document Name) and the URL (must start with http://) and click OK
So how does it work? The Content Type has a template that is an ASPX page that contains a server side control named SharePoint:UrlRedirector. When this page is rendered it simply redirects to the address listed in the items URL property. Also experiment with adding these built-in content types to your library:
  • Basic Page
  • Web Part Page
  • Dublin Core Columns (Do a web or wikipedia.com search for "Dublin Core")
  • Picture

You can also add customized folders to the New dropdown. See here. Need to add custom columns / meta data to any of the above? Just create a new Content Type based on one of the above and add it to your library. See here.

.

65 comments:

Anonymous said...

Solved my quandary perfectly! Thank you!

Anonymous said...

Hi, thanks for the post, is it possible to access the metadata using the link that we have added by using this process.

Mike Smith said...

Anonymous,

Not by using this option. But I think you could write one to do so. (something to put on my todo list!)

Mike

Anonymous said...

Yes, you can have a link with metadata, but you have to ditch the predefined option and create one yourself.

Here is where I got the info to add metadata to Links to Documents: http://www.toddklindt.com/blog/Lists/Comments/ViewComment.aspx?ID=226

Anonymous said...

Thank you thank you! been wondering about this for ages.

Jesse Palmer said...

Wow. I fumbled around Microsoft's "help" pages for about 15 minutes before I went back to Google to search again. Up popped your post and it showed me exactly what I needed to do. Thanks!

Anonymous said...

Thanks Mike, works a treat. It also allows you to link to other folders!

Anonymous said...

I do not have the "settings" option on my menu. Just "new", "upload", "actions" options.

Do I need different authority from my admin area?

CJ

Mike Smith said...

> I do not have the "settings" option on my menu. Just "new", "upload", "actions" options.

You have "Member/Contributor" permissions. You will need "Designer" or "Owner/Full Control" permissions to see Settings.

Mike

Rajni said...

Perfect !!! Thanks for this post and it worked well for my requirement.

Josh said...

Finally!! Thanks for the information. Just what I have been looking for.

Anonymous said...

My problem is that the documents are on a media server where the link does not start with http. Is there a way to link to a file that starts with mms://?

Mike Smith said...

> Is there a way to link to a file that starts with mms://?

Yes.

1) use notepad to create a text file named redirect.htm (or any name you choose that ends with .htm)

2) In this file add this little JavaScript routine

<script>

window.location.href = window.location.search.substring(1);

</script>

3) upload this file to a library in SharePoint and note the URL (something like http://yourserver/sites/yoursite/shared documents/redirect.htm)

4) When you add a new Link to Document enter the URL this way:

http://yourserver/sites/yoursite/shared documents/redirect.htm?mms://pathtoyourdocument

Mike

Anonymous said...

Thanks! I will try that

Sam Varghese said...

Perfect.. exactly what I wanted. Thanks.

TheGoat said...

Hi Mike, yet another SharePoint newby you have solved a problem for (site deserves to be top of Google etc)

Is it possible to get links in document libraries to open in a new window?

Mike Smith said...

TheGoat,

> Is it possible to get links in document libraries to open in a new window?

Yes. It would be a variation of this article:

http://techtrainingnotes.blogspot.com/2009/07/sharepoint-adding-popups-to-link-lists.html


I'll see if I can put together a new article to add "Open in new window" to a document library.

Mike

Anonymous said...

Does the above "adding hyperlinks" function only work with the non-free version of sharepoint?

Mike Smith said...

Anonymous,

Yes it is in both WSS and MOSS and in Foundation 2010 and Server 2010.

Mike

Anonymous said...

Mike -- You're the best. Thanks for the post.

Anonymous said...

Thank you for the post. Quick question. I do not have a multimedia server, just a data server. Is there a way to link documents that are stored locally: //myserver/folder/doc.doc

Mike Smith said...

Anonymous,

Link to a Document will only work with URLs that start with http:// or https://

You could create a web page using notepad and save it with an ASPX extension (mydocument.aspx) to a SharePoint library. The page would only have the following content:

<a href="#" onClick="history.go(-1)">Return to the library</a>

<script>
document.location="file://DEMO2010A/SampleDocs/adventureworksbikes.xls"
</script>

You would need to create one of these files for each document you want to link to.

Mike

Anonymous said...

Mike,

That's what I figured. I will look into your solution. Thank you again. Cheers!

Anonymous said...

Hi Mike,

I get a message that says "The specified item or folder name is too long. The URL path for all items and folders must be 260 characters or less (and no more than 128 characters for any single item or folder name in the URL). Please type a shorter item or folder name."

I copied/pasted the link to the site where my other reports are located...is there a way to shorten the link and still get to the same webpage?

Anonymous said...

Excellent clear instructions. Answered my question perfectly.

Shar

Mark said...

Nice post!

I was wondering though if you can use this same option but then having the document opening in Edit mode.

Any ideas?

Br,
Mark

Mike Smith said...

Mark,

I'm working on an article on how do duplicate all of the menu links, and I may have found a way to do what you want, but it will be a week or so before I can document and post that. Check back...

Mike

Anonymous said...

Great post, but be aware the redirect code doesn't appear to work in FireFox, i.e.

window.location.href = window.location.search.substring(1);

CH said...

This does not work for me it opens an excel spreadsheet, any suggestions?

I have tried inserting the link at the top of the spreadsheet where it asks for a URL and a name and it does show up in the properties?

Mike Smith said...

CH,

You added the Content Type to the library, added a New Link to a document, entered the URL to your Excel file in another library or site and then clicked the link?

What did you want it to open if not the Excel file? (I may not be understanding your question...)

Mike

Nick said...

Wondering if there is any way to make these links to documents/folders work in Windows Explorer? I get an .aspx webform file there instead of a useable link. Would love to have my links work in explorer as well...

Mike Smith said...

Nick,

No way I know of. A library stores files, and the Link to a document feature creates an ASPX file that includes redirect code. So all that is seen by Windows Explorer is the ASPX file.

Mike

Anonymous said...

Awesome. Thanks for the help.

Stacie said...

Hi

I use SharePoint 2007 and am trying to create links to documents elsewhere on the site, I.E from one document library to another. The only option I get though is to link the document library - not the actual document itself. Is it possible to do this, or can I only link the library?

Thank you,

Mike Smith said...

Stacie,

Just go to the document library and right-click the document you want to link to, click Properties, and copy the complete URL. Paste this URL into the new Link To A Document item.

Mike

manasa said...

Hello All,
you can link your server file's also using edit properties option. there u have to change http to file. example File://J:\Hello\hello.xlsx

Anonymous said...

Hi, I have a document library with several folders in side. When I try to create a link in one of those folders in the library, it is created or referenced in all the folders. is there a way to just have the link in one folder instead on all to folders?

Mike Smith said...

F. Hilman,

> When I try to create a link in one of those folders in the library, it is created or referenced in all the folders.

"Link to a Document" is just an ASPX file that is added to the library or a folder within the library. I can't think of any way it would show up in another folder.

Mike

Anonymous said...

I would like to add a web part which shows the graphics of the URL site on sharepoint without actually re-directing to the site. Is this possible?

Mike Smith said...

Anonymous,

> without actually re-directing to the site

If you just want a web part to display an image or a page, use a Page Viewer web part or use a Content Editor Web Part and add the HTML for an IFRAME.

Or do you want to click a link in a document library to display the image?

Anonymous said...

Is there any way to to file the link with column headings created on the page? It doesn't give me an option and then the link doesn't group in the grouping settings I have set up for the page.

Mike Smith said...

Anonymous,

You can add meta data columns to the Link to a File item. Link to a File is a Content Type, so you can make a copy of it and add columns.

Go to your top level site.
Go to Site Actions, Site Settings, Content Types.
Find the Link to a File content type, copy it and add the columns needed.

Anonymous said...

I am unable to open .aspx files in a doc lib post migration to SP 2010.All the other files are coming up fine like word, excel, pdf.

Only a blank page opens up when clicked on the .aspx file

Mike Smith said...

> I am unable to open .aspx files

No error at all? Is there anything in the SharePoint or Windows event logs?

What happens when you create a new Page or Web Part Page in 2010?

Did the pages use a custom master page when in 2007?

You may want to post your question here: http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010setup/threads

Mike

Stephanie said...

Thanks so much Mike! Your instructions are very clear and helpful. I've been wondering how to do this for months and thrilled to find out how finally!

Unknown said...

I have sharepoint foundations 2010 installed on windows home server 2011. How can I access the whs 2011shared folders in sharepoint foundations? Do i have to build a hyperlink to every document in the share?

Thanks

Mike Smith said...

Gregory,

I have not used WHS so I have no idea! :-)

Try posting your question in the TechNet forums for WHS or SharePoint 2010.

Mike

Anonymous said...

Hi Mike - If a person is using Safari to access an Intranet site (SharePoint 2007, MOSS), what is the syntax to enable Safari to open an Excel file (located on a network share)? In SharePoint I have tried the following link File://ServerName/FilePath/filename.extension. In Internet Explorer this path works fine when opening the Excel file but the Excel file does not open when clicking the link from Safari. Any help you could give would be greatly appreciated. - Jodi

Mike Smith said...

I don't use Safari, so I can't test one way or the other. In any case I don't think SP 2007 is very friendly with non-IE browsers. SP 2010 and 2013 are much better across browsers.

Did you try using http?

http://ServerName/FilePath/filename.extension

Anonymous said...

This tutorial was so helpful. I struggled to solve this problem for quite some time via MS help. THANK YOU!!!

Rick said...

I created a link to another site on my server. I used the (Click here to test) and it worked perfectly. However, when I click the link from my library it takes me to a blank site. That according the bread crumbs is a blank site under my library. Any ideas?

Anonymous said...

Thank for your tips, but when I click click new link, it always prompt upload document windows. Please help

Dan Lussier said...

Hi Mike.

Great explanation. Simple and to the point.

Follow up question for you - If I have added the Basic Page content type to my Document Library, how do I go about modifying the appearance of the Basic Page template? I'd like to have some formatting such as the Quick Launch bar on the left side and the Text Layout button on the ribbon.

Any advice?

Kipper Bush said...

I know this was not an option enabled by default for me.

This blog post show how to do better than I can explain.

http://aaclage.blogspot.com/2011/09/how-to-add-links-in-document-library.html

Tim said...

This works great and allows us to create a central library of important stuff. Thanks for the info.

Paula said...

Hi Mike,
Thank you for being so well versed on this feature. I am looking for a variation to this solution. I would like the new item list to link to a document where the location is a fixed network address (so the users don't need to know the path-it is already provided). Essentially the template for a file is located elsewhere and I don't want it duplicated in this library. I tried to add the .ASPX file as the template however it opens my default web editor (SharePoint Designer) when selected. Any suggestions?
Thanks,
Paula

Dick said...

Sorry if this appears twice. after signing in with Google my comments box reappeared empty.

Brilliant article Mike. Solved a huge problem for me. Do you know if it is possible to apply this to the root of a site and have it update all document libraries underneath and/or any new libraries created

Mike Smith said...

Rick,

No. Content Types need to be added to each library individually.

One option: Write a PowerShell script that scans all of your libraries and if the Content Type is not there, add it.

As far as new libraries, you can add the Content Type to an existing library, save it as a template and then ask site owners to create new libraries from that template.

Mike

Anonymous said...

Brilliant!!!
(I was attempting to upload a shortcut!)

Anonymous said...

Dude you just saved the fricken day! Thank you !!

Anonymous said...

Thank you very much for all of this!

The "link to a document" portion was perfect!

As Ringo would say . . . "Peace & Love!"

Unknown said...

Is there a way that, once you've got your link etc. done, you can make the page open on itself rather than in a new tab?

Mike Smith said...

Ed,

> make the page open on itself rather than in a new tab?

Not directly to the Link to a Document Content Type, or to a single Link to a Document link. You could edit the view's page in SharePoint Designer and add some JavaScript that changes the link behavior. Let me know if this is of interest, and I'll look into it.

Mike

Igor Torrealba said...

Hi Mike,

I used your post to add the type Wiki enterprise page. It is now visible in the drop down under New Document but I get an error, this is the content

"Error
An unexpected error has occurred.

Troubleshoot issues with Microsoft SharePoint Foundation.

Correlation ID: 3a7bada7-e0fd-47bc-9bc9-c1c906cf533d

Date and Time: 11/25/2017 9:13:43 AM"

What do you think I should do?

Thanks a lot!

Mike Smith said...

Igor,

Tell me more about your SharePoint:
version: 2007, 2010, 2013, 2016, SharePoint Online, SharePoint Online Modern UI?
edition: Foundation, Standard, Enterprise?
Anything custom in that library? Event receivers, workflows, other content types?

You could send the Correlation ID and Date and Time to your server admins so they can lookup the error.

Mike

Note to spammers!

Spammers, don't waste your time... all posts are moderated. If your comment includes unrelated links, is advertising, or just pure spam, it will never be seen.