Microsoft.SharePoint.WebCon ...


ContentDatabaseSection Class (Microsoft.SharePoint.WebControls)

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

Visual Basic (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 ContentDatabaseSection
    Inherits UserControl
Visual Basic (Usage)
Dim instance As ContentDatabaseSection
C#
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] 
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel=true)] 
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] 
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel=true)] 
public class ContentDatabaseSection : UserControl
Inheritance Hierarchy

System.Object
   System.Web.UI.Control
     System.Web.UI.TemplateControl
       System.Web.UI.UserControl
        Microsoft.SharePoint.WebControls.ContentDatabaseSection
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

Tags :


Community Content

Thomas Lee
ContentDatabaseSection (Part1)

Description

The Microsoft.SharePoint.WebControls.ContentDatabaseSection class inherits System.Web.UI.UserControl and provides methods and properties to build the required UI components for the initial setup of a Web application’s content database. These components are:

1) InputFormSection control that contains this control.

2) InputFormRadioButton controls (i.e. RadWindowsAuth ) to specify whether Sql or Window authentication must be used.

3) A drop down list (DdlSearchServer) that specifies Search Service instance.

4) InputFormSection that contains Search Service instance drop down list.

5) Several TextBox controls (i.e. TxtDatabaseAccount ) to collect data such as database server name, password, user name and etc.

6) Several required field validation controls (i.e. ReqValDatabaseAccount ) to validate the data of child input controls.

7) Several labels to provide description to child input controls.

This control exposes a public property called DisplayMode (of type ContentDatabaseSectionMode Enumeration), which puts the control in different display modes. For example, in Default mode, all of child controls are enabled, where as in other two modes (Disabled and AuthenticationEdit), some or all of controls are disabled.

This control is mostly used in custom Web parts or Web part pages targeted at Central administration Web application or any other sites meant to be used for administrative purposes. End users typically don’t need to interact with Web application content databases.

The Usage Scenario

To customize your forms to contain content database section, you can follow two approaches:

1) You can extend ContentDatabaseSection classto define your own custom control that deals with the content databases of your Web application. You can create a class library that inherits ContentDatabaseSection class, implement your custom logic and copy the DLL of your project to the global assembly cache (GAC). You also need to add an .ascx file containing your custom control template definition (which references the custom DLL) to <%WSS System Directory%>\TEMPLATE\ADMIN folder.

2) You can reuse out of the box ContentDatabaseSection user control (locatedin <%WSS System Directory%>\TEMPLATE\ADMIN) in your Web parts or Web part pages. This can be done either declaratively or using a programmatic approach by loading it dynamically and add it to the control collection of either your Web part or Web part page. Below is one example of loading the user control programmatically in CreateChildControls event of a Web part:

C# Code Example

ContentDatabaseSection cdsCtrl = (ContentDatabaseSection)Page.LoadControl("~/_admin/ContentDatabaseSection.ascx"); 
cdsCtrl.ID = "CDS";
this.Controls.Add(cdsCtrl);

Visual Basic .NET Code Example

Dim cdsCtrl As ContentDatabaseSection = DirectCast(Page.LoadControl("~/_admin/ContentDatabaseSection.ascx"), ContentDatabaseSection) 
cdsCtrl.ID = "CDS"
Me.Controls.Add(cdsCtrl)

Reza Alirezaei - MVP
ContentDatabaseSection (Part2)

The following code samples demonstrate another usage scenario of ContentDatabaseSection user control in a declarative way. In this example the user control is hosted in a custom Web part page (placed in %WSS System Directory%\12\TEMPLATE\ADMIN) to display the current authentication type of a content database while allowing user to change it from Sql to Windows or vice versa.

First you need to create a custom page named ChangeConDBAuthType.aspx, then register a tag that points to the following user control:

<%@ Register TagPrefix="wssuc" TagName="ContentDatabaseSection" src="~/_admin/ContentDatabaseSection.ascx" %>

Once the above tag is registered, you can reference the control later in the page like below and specify the properties and their respective values.

<wssuc:ContentDatabaseSection Id="ContentDatabaseSection" Title="<%$Resources:spadmin, multipages_ContentDatabase_title%>" IncludeSearchServer="true" runat="server" />

Thomas Lee
ContentDatabaseSection (Part3) : ChangeConDBAuthType.aspx
<%@ Assembly Name="Microsoft.SharePoint.ApplicationPages, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Page Language="C#" Inherits="SDKBounty.ContentDBChangeAuthType,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="wssuc" TagName="ContentDatabaseSection" src="~/_admin/ContentDatabaseSection.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="ButtonSection" src="~/_controltemplates/ButtonSection.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="Change Authentication Type" EncodeMethod="HtmlEncode" runat="server"/>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderPageDescription" runat="server">
<wssuc:ToolBar id="onetidNavNodesTB" runat="server">
<Template_RightButtons>
<wssawc:EncodedLiteral ID="EncodedLiteral1" runat="server" Text="Content DBs: "></wssawc:EncodedLiteral>
<asp:DropDownList id="ddlContentDBs" runat="server" AutoPostBack="true" OnSelectedIndexChanged="CDBSelection_Change" />
<SharePoint:WebApplicationSelector id="Selector" runat="server" OnContextChange="Selector_OnContextChange" AllowAdministrationWebApplication="false" />
</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>
<TABLE border="0" width="100%" cellspacing="0" cellpadding="0">
<wssuc:ContentDatabaseSection Id="cdsCtrl"
Title="Change Authentication Type"
IncludeSearchServer="false"
runat="server" />
<wssuc:ButtonSection runat="server">
<Template_Buttons>
<asp:Button UseSubmitBehavior="false" runat="server" class="ms-ButtonHeightWidth" OnClick="BtnSubmit_Click" Text="Change" id="BtnCreateSite"/>
</Template_Buttons>
</wssuc:ButtonSection>
</TABLE>
</asp:Content>

Thomas Lee
ContentDatabaseSection (Part4)

C# Code Example (Code Behind)

public class ContentDBChangeAuthType : LayoutsPageBase
{
protected Label Message;
protected WebApplicationSelector Selector;
protected DropDownList ddlContentDBs;
protected ContentDatabaseSection cdsCtrl;
protected Button BtnCreateSite;
protected override void OnInit(System.EventArgs e)
{
cdsCtrl.Description = "Your description goes here";
cdsCtrl.DisplayMode = ContentDatabaseSectionMode.AuthenticationEdit;
base.OnInit(e);
}
protected void Selector_OnContextChange(object sender, EventArgs e)
{
SPWebApplication selectedWebApplication = Selector.CurrentItem;
int contentDBs = selectedWebApplication.ContentDatabases.Count;
if (!Page.IsPostBack && contentDBs >= 1)
FillContentDBList();
}
protected void BtnSubmit_Click(object sender, EventArgs e)
{
//Your code to change the authentication type
}
protected void CDBSelection_Change(object sender, EventArgs e)
{
FillContentDBList();
}
private void FillContentDBList()
{
SPWebApplication selectedWebApplication = Selector.CurrentItem;
foreach (SPContentDatabase cdb in selectedWebApplication.ContentDatabases)
{
ddlContentDBs.Items.Add(cdb.Name);
cdsCtrl.DatabaseServer = cdb.Server;
cdsCtrl.DatabaseName = cdb.Name;
}
}
}

Thomas Lee
ContentDatabaseSection (Part5)

Visual Basic .NET Code Example (Code Behind)

Public Class ContentDBChangeAuthType
Inherits LayoutsPageBase
Protected Message As Label
Protected Selector As WebApplicationSelector
Protected ddlContentDBs As DropDownList
Protected cdsCtrl As ContentDatabaseSection
Protected BtnCreateSite As Button

Protected Overloads Overrides Sub OnInit(ByVal e As System.EventArgs)
cdsCtrl.Description = "Your description goes here"
cdsCtrl.DisplayMode = ContentDatabaseSectionMode.AuthenticationEdit
MyBase.OnInit(e)
End Sub
Protected Sub Selector_OnContextChange(ByVal sender As Object, ByVal e As EventArgs)
Dim selectedWebApplication As SPWebApplication = Selector.CurrentItem
Dim contentDBs As Integer = selectedWebApplication.ContentDatabases.Count
If Not Page.IsPostBack AndAlso contentDBs >= 1 Then
FillContentDBList()
End If
End Sub
Protected Sub BtnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs)
'Your code to change the authentication type
End Sub
Protected Sub CDBSelection_Change(ByVal sender As Object, ByVal e As EventArgs)
FillContentDBList()
End Sub
Private Sub FillContentDBList()
Dim selectedWebApplication As SPWebApplication = Selector.CurrentItem
For Each cdb As SPContentDatabase In selectedWebApplication.ContentDatabases
ddlContentDBs.Items.Add(cdb.Name)
cdsCtrl.DatabaseServer = cdb.Server
cdsCtrl.DatabaseName = cdb.Name
Next
End Sub
End Class

Reza Alirezaei - MVP
Screenshot

For the screenshot of the above content see: http://blogs.devhorizon.com/reza/?p=655


Tags : screenshot

Page view tracker