SiteAdministrationSelector Class (Microsoft.SharePoint.WebControls)
SiteAdministrationSelector Class (Microsoft.SharePoint.WebControls)

Namespace: Microsoft.SharePoint.WebControls
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
Syntax

'Usage

Dim instance As SiteAdministrationSelector


'Declaration

<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level:=AspNetHostingPermissionLevel.Minimal)> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel:=True)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level:=AspNetHostingPermissionLevel.Minimal)> _
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel:=True)> _
Public Class SiteAdministrationSelector
    Inherits ContextSelector(Of SPSiteAdministration)
Inheritance Hierarchy

System.Object
   System.Web.UI.Control
     System.Web.UI.WebControls.WebControl
       Microsoft.SharePoint.WebControls.ContextSelector
        Microsoft.SharePoint.WebControls.SiteAdministrationSelector
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also

Community Content

SiteAdministrationSelector (Part 1)
Added by:Thomas Lee

Description

The Microsoft.SharePoint.WebControls.SiteAdministrationSelector class inherits from Microsoft.SharePoint.WebControls.ContextSelector, providing a way to switch between all site collections in a given Web application using a pop up window. You can place this Web control in the PlaceHolderPageDescription place holder of your page and surround it with ToolBar and Template_RightButtons tags to create a toolbar that has this control rendered as a drop down list located on the right side.

You can control the appearance and behavior of the SiteAdministrationSelector control by setting properties defined in this class. For example, AllowAdministrationWebApplication set to true specifies that Central administration site should also appear in the available Web applications.

By setting AllowPopup property to false, instead of getting the out of the box SelectSite.aspx in a pop up window, you will be transferred to SelectSite.aspx page passing the required information in query string such Mode, WebApplicationId ,ReturnSelectionPage and AllowAdministrationWebApplication if it is false.

SiteAdministrationSelector.CurrentItem returns an object of type SPSiteAdministration. If you disassemble SPSiteAdministration and look at its internal constructor, you will see that if the current user is an administrator in the server farm, it sets AdministratorOperationMode property to true which turns the SPSite object into a special mode that allows administrative functions to be performed on it. Since the resultant SPSite object is not returned, you need to do some more coding to get the SPSite object corresponding to what user selects in the control.

The Microsoft.SharePoint.WebControls.SiteAdministrationSelector class exposes a ContextChange event which can be used to control the behavior of the control when user changes the context.

The Usage Scenario

The following code samples show how you might use the SiteAdministrationSelector control in a custom Web part page (placed in %WSS System Directory%\12\TEMPLATE\ADMIN) named ShowSiteUsage.aspx to display all templates used in a given site collection,

This example requires using directives (Imports in Visual Basic) for the Microsoft.SharePoint.WebControls, Microsoft.SharePoint.Administration and System.Web.UI.WebControls namespace.

ShowSiteUsage.aspx

<!--[...Ommitted as community content has number of characters limitation.See below for complete code.]--> 
<wssuc:ToolBar id="onetidNavNodesTB" runat="server">
<Template_RightButtons>
<SharePoint:SiteAdministrationSelector id="Selector" runat="server" OnContextChange="Selector_OnContextChange" AllowAdministrationWebApplication="false" AllowPopup="true" />
</Template_RightButtons>
</wssuc:ToolBar>
<!--[...Ommitted as community content has number of characters limitation.See below for complete code.]-->
siteadministrationselector (Part 2)
Added by:Thomas Lee

C# Code Example (Code Behind)

public class ShowSiteUsage : LayoutsPageBase
{
protected Label Message;
protected SiteAdministrationSelector Selector;
protected override void OnInit(System.EventArgs e)
{
base.OnInit(e);
}
protected void Selector_OnContextChange(object sender, EventArgs e)
{
SPSiteAdministration selectedSiteAdmin = Selector.CurrentItem;
using (SPSite oSiteCollection = new SPSite(selectedSiteAdmin.Url))
{
SPSite.UsageInfo oUsageInfo = oSiteCollection.Usage;
long lngStorageUsed = oUsageInfo.Storage;
Message.Text = "Site Collection URL: " + oSiteCollection.Url +
" Storage: " + lngStorageUsed.ToString() + "<BR>";
}
}
}

Visual Basic .NET Code Example (Code Behind)

Public Class ShowSiteUsage
Inherits LayoutsPageBase
Protected Message As Label
Protected Selector As SiteAdministrationSelector
Protected Overloads Overrides Sub OnInit(ByVal e As System.EventArgs)
MyBase.OnInit(e)
End Sub
Protected Sub Selector_OnContextChange(ByVal sender As Object, ByVal e As EventArgs)
Dim selectedSiteAdmin As SPSiteAdministration = Selector.CurrentItem
Using oSiteCollection As New SPSite(selectedSiteAdmin.Url)
Dim oUsageInfo As SPSite.UsageInfo = oSiteCollection.Usage
Dim lngStorageUsed As Long = oUsageInfo.Storage
Message.Text = "Site Collection URL: " + oSiteCollection.Url + " Storage: " + lngStorageUsed.ToString() + "<BR>"
End Using
End Sub
End Class
siteadministrationselector (Part 3) :ShowSiteUsage.aspx
Added by:Thomas Lee

<%@ Assembly Name="Microsoft.SharePoint.ApplicationPages, Version=12.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c" %>
<%@ Page Language="C#" Inherits="SDKBounty.ShowSiteUsage,SDKBounty, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=2e879e7dc8b7c3e9" MasterPageFile="~/_layouts/application.master" %>
<%@ Register TagPrefix="wssuc" TagName="ToolBar" src="~/_controltemplates/ToolBar.ascx" %>
<%@ Register TagPrefix="wssawc" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint,
Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"Assembly="Microsoft.SharePoint,
Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server">
<SharePoint:EncodedLiteral ID="TitleArea"Text="Site Usage" EncodeMethod="HtmlEncode" runat="server"/>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderPageDescription" runat="server">
<wssuc:ToolBar id="onetidNavNodesTB" runat="server">
<Template_RightButtons>
<SharePoint:SiteAdministrationSelector id="Selector" runat="server" OnContextChange="Selector_OnContextChange"
AllowAdministrationWebApplication="false" AllowPopup="true" />
</Template_RightButtons>
</wssuc:ToolBar>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<asp:Label ID="Message" class="ms-info" runat="server"></asp:Label>
</asp:Content>

Screenshots
Added by:Reza Alirezaei - MVP

For screenshots of the content above , please visit : http://blogs.devhorizon.com/reza/?p=645

Make sure you dispose the SiteAdministrationSelector properly
Added by:Jeroen Ritmeijer
It is completely undocumented, but make sure you call Dispose() on CurrentItem.

For details see http://www.muhimbi.com/blog/2009/08/additional-little-known-sharepoint.html
© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View