Monday, May 21, 2012

Get current zone in SharePoint 2010

In this article we will discuss how to know about the zone of the incoming request.

Also you can check out some posts on:

- SPLimitedWebPartManager Class in SharePoint 2010

- Differences Between Sandboxed and Farm Solutions in SharePoint 2010

- Create a sequential workflow using Visual studio 2010 in SharePoint 2010

To know the zone of a request we can use the SPContext.Current.Site.Zone class. You can check some an Article on SPContex class in SharePoint 2010. This returns an enum of SPUrlZone which represents wether its a Default zone, Intranet Zone, Internet Zone, Custom Zone or Extranet Zone.

This is presented in Microsoft.SharePoint.Administration namespace and also this is available in Sandboxed solution.

Here is a code sample:

using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

                    string Zone = string.Empty;
                    if (SPContext.Current.Site.Zone == SPUrlZone.Extranet)
                    {
                        Zone = "Extranet";
                    }
                    else if (SPContext.Current.Site.Zone == SPUrlZone.Internet)
                    {
                        Zone = "Internet";
                    }
                    else if (SPContext.Current.Site.Zone == SPUrlZone.Intranet)
                    {
                        Zone = "Intranet";
                    }
                    else if (SPContext.Current.Site.Zone == SPUrlZone.Custom)
                    {
                        Zone = "Custom";
                    }
                    else if (SPContext.Current.Site.Zone == SPUrlZone.Default)
                    {
                        Zone = "Default";
                    }

No comments:

Post a Comment