SharePoint Tip/Trick: Specifying a Relative Portal Site Connection Link
Posted by DevExpert on May 5th, 2009
There are a variety of reasons why you’d want to create multiple site collections – to avoid recommended capacity limits, to provide a logical site structure, etc. One of the drawbacks with creating multiple site collections is the lack of out-of-the-box functionality to access and share content across site collections. While portal site connections don’t do anything to access or pull content, it does allow you to specify a “connection” to another site collection, which appears in the global breadcrumb. This makes logical navigation easier. Consider the following example: a company needs to have separate site collections for each department (HR, accounting, IT, etc.), but there is also a “top-level”, shared area of the environment, which will be a separate site collection. When you’re in each of the departmental site collections, it would make sense to have a link back to the top-level site collection, to insinuate a logical hierarchy. Simply put, a portal site connection gives you a breadcrumb link to another site collection.
Let’s take a look at the above example. I created a root site collection (http://intranet.devexpertise.com), and also an accounting site collection (http://intranet.devexpertise.com/sites/accounting). When you’re on the accounting site collection, there’s no visual indication or link back to the “root” site collection:
By simply adding a portal site connection, we can provide a visual indication of the logical hierarchy and link back to the root site collection. To add a portal site connection, navigate to Site Settings > Site Collection Administration > Portal site connection, and specify a URL and a friendly name for the link:
Now, the breadcrumb will show a link to the root site collection:
Great! …as long as you’re always going to access your sites from a single URL. What if you have multiple URLs set up, such as the situation if you allow external access to your environment and have a separate external URL (http://extranet.devexpertise.com). The logical thing would be to just specify a relative link for the portal web address, however SharePoint won’t let you, and pops up a nice “Please enter a URL for the portal site” error:
Why is this really a problem? Well, let’s say you left it as http://intranet.devexpertise.com, and accessed it from http://extranet.devexpertise.com. The portal site connection link would still point to the intranet!
Lovely, huh? Fortunately, you are able to easily set this to a relative link using a few lines of code:
using (SPSite siteCollection = new SPSite("http://intranet.devexpertise.com/sites/accounting")) { siteCollection.PortalUrl = "/"; }
That’s it! Now, no matter what URL you access the accounting site from, the portal site connection link will jump you back to the correct root site collection:
May 29th, 2009 at 12:16 pm
Where do I put this code to make this work? Do I have to write a feature or webpart to encapsulate it?
June 2nd, 2009 at 8:03 am
Bob, you could do this in a web part or feature, but the code is just a little console application utility I wrote and just ran it on the server itself. It’s completely up to you though…
Good luck!
August 3rd, 2009 at 8:20 am
I am looking for this functionality, but am not following how/where to use the code. I would really appreciate if you could elaborate.
Thanks!
August 15th, 2009 at 9:46 am
Bernard, this code has to be run ON the SharePoint server — however you go about doing that is up to you. I just used a simple Console application, but you could build a web part that does this also. Does that make sense?
August 30th, 2009 at 9:10 pm
This is awesome!! I just put the code in the layouts directory and ran it! Thanks so much!!
December 19th, 2009 at 12:32 pm
Will this structure allow for sharing between sites?