One of things I found that I had to do a lot with the upgraded site (or even a new, from scratch, portal) was to connect the various web applications and site collections to the main portal (results in adding a link to the top left bread crumb trail). This can be doing by going to Site Settings and click the Portal Site Connection link. Doing this programmatically is just about as simple. All that is required is to set the PortalUrl
and PortalName
properties of the SPSite
object. You can see this in the code below:
1using (SPSite siteCollection = new SPSite(url))
2{
3 if (!disconnect)
4 {
5 string portalurl = keyValues["portalurl"];
6 string portalname = keyValues["portalname"];
7 siteCollection.PortalUrl = portalurl;
8 siteCollection.PortalName = portalname;
9 }
10 else
11 {
12 siteCollection.PortalUrl = null;
13 }
14}
To disconnect a site collection from a portal you simply set PortalUrl
to null. The syntax of the command I created to do this can be seen below.
C:\>stsadm -help gl-connecttoportalsite
stsadm -o gl-connecttoportalsite
Connects a site collection to a portal.
Parameters:
-url <site collection>
[-portalurl <portal web address>]
[-portalname <portal name&g;]
[-disconnect]
Here’s an example of how to set the portal site connection:
stsadm –o gl-connecttoportalsite –url "http://mysites/" –portalurl "http://intranet/" -portalname "Corporate Portal"
If you want to disconnect from a portal do the following:
stsadm –o gl-connecttoportalsite –url "http://mysites/" –disconnect