MOSS MVP

I've moved my blog to http://blog.falchionconsulting.com!. Please update your links. This blog is no longer in use--you can find all posts and comments at my new blog; I will no longer be posting to this site and comments have been disabled.

Thursday, August 9, 2007

Portal Site Connection

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:

   1: using (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

7 comments:

Richard said...

I followed your instructions to the letter - only to get an "Access Is Denied" exception. The portal site and the MySite are on the same server, but on seperate web applications (different ports).

Any ideas?

Gary Lapointe said...

Richard - My setup is effectively the same as yours (except I'm using host headers instead of ports) and it worked fine for me. Most likely you've got some permissions issue - make sure that you are a site admin for the root my site host site. Also - under policies for web applications (http://centraladminhost:port/_admin/policy.aspx make sure that your account has full control for the my sites web application. Hope this helps.

Jack said...

Gary,

First of all thanks for the great tools and also that you share the sourcecode with the community.

I've also developed a script for automated install of sharepoint and was developing some extra commands but why re-invent the wheel ;-)

anyway all functions are working in my test moss 2007 sp2 setup except this one :

stsadm -o gl-connecttoportalsite -url http://home -portalurl http://intranet -portalname "Portal"

retyped the -'s removed and added the "" but still get commandline error.

Thanks.

Anonymous said...

Hi Gary! Thanks a lot for all the great commands!

I had a question regarding this one: Is it possible to set the portal connection to go to the Corporate portal for an entire web application? For instance, we have "My Sites" hosted in a separate web application and I want all My Sites to have the portal connection in the breadcrumb. This should be set automatically for new My Sites as well. Is this possible??
Thanks in advance!

Gary Lapointe said...

Use a feature stapler to update the setting whenever a new my site is created.

Anonymous said...

Thanks for your reply.
What is a 'feature stapler'. I am not aware of that... Could you please elaborate?

Also I did find another way to apply the connection to the portal site automatically(for New My Sites):
Go to the My Sites settings page (e.g. http://mysites/_layouts/settings.aspx). Go to 'Portal connection' and enter the portal URL and name.
This will enable NEW My Sites to get back to the main portal via the breadcrumb.
I am still trying to get this done for existing My Sites.

Anonymous said...

I ran this command and it works greta for new My Sites. However, for existing ones, the breadcrumb on the home page of a My Site deos not work. The breadcrumb on the profile page of the My Site takes you back to the fornt portal.
Any suggestions? Am I missing something?