Programmatically Configure the Portal Site Collection in SharePoint 2010


In this article we will be seeing how to add a site collection link to global breadcrumb navigation (Navigate Up button portal1.gif) in SharePoint 2010 using the SharePoint Object model.

Portal Site Collection:

A Portal Site Collection is used to link from one site collection to another site collection. The Portal site will be added to the Navigate Up (global breadcrumb navigation).

Programmatically Configure Portal Site Collection:

  1. Open Visual Studio 2010.
     
  2. On the File Menu, click on New and then click on Project.
     
  3. Select the Console Application template from Installed templates.
     
  4. Check whether the project is targeted to .NET Framework 3.5.
     
  5. Enter the Name for the project and then click on Ok.
     
  6. Right click on the project and then click on Properties.
     
  7. Click on Build tab, and check whether the Platform Target is selected as Any CPU.
     
  8. Add the following reference.

    i) Microsoft.SharePoint.dll
     
  9. Add the following namespace.

    i) Using Microsoft.SharePoint;
     
  10. Replace Program.cs with the following code.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.SharePoint;

    namespace PortalSiteCollection
    {
        class Program
        {
            static void Main(string[] args)
            {
                using (SPSite site = new SPSite("https://serverName:1234/sites/Sample/"))
                {
                    site.PortalName = "Sample Link";
                    site.PortalUrl = "https://serverName:1236/sites/Test/";
                }
            }
        }
    }

     

  11. Build the solution.
     
  12. Hit F5.
     
  13. Go to the SharePoint 2010 site collection.
     
  14. Click on Navigate Up, you will be able to see a new link added as shown in the following.

    portal5.gif
     
  15. When you click on the Sample Link, you will be redirected to the corresponding portal site. 

Up Next
    Ebook Download
    View all
    Learn
    View all