The web page contains a text box to enter the site URL. By clicking the submit button, web page populates the dropdown list with sub sites details if it exists and displays the site information.
First of all you will need to add the Microsoft.SharePoint.dll to your web application reference list. This will give us the access to the SharePoint Object Model.
Then instantiate the SPSite object as displayed below. I have written this code in Click event of the Submit button. The absolute URL is passed in through the txtWSSSiteUrl text box. This will populate site collection for the given URL.
//Get the site collection
SPSite mySiteCollection = new SPSite(txtWSSSiteUrl.Text);
Then to access an individual site, instantiate the SPWeb object as displayed below. I am passing in the site name as a parameter.
//Get the details of the selected WSS site
SPWeb site = mySiteCollection.AllWebs[siteName];
After constructing the site SPWeb object, the developer can access the information of the site using the public properties of the SPWeb object as displayed below.
AllowAnonymousAccess Property
//Gets a Boolean value that specifies whether anonymous access is allowed for the site.
LbAllowAnonymouseAccessData.Text = site.AllowAnonymousAccess.ToString();
AllowUnsafeUpdates Property
//Gets a Boolean value that specifies whether to allow updates to the database as a result of a GET request.
LbAllowUnsafeUpdatesData.Text = site.AllowUnsafeUpdates.ToString();
AllUsers Property
This property returns a SPUserCollotion object. It's a collection of users.
//Gets the collection of user objects that represents all users who are either members of the site or who have browsed to the site as authenticated members of a domain group in the site.
SPUserCollection users = site.AllUsers;
The above code gets the collection of users.
//Create a Data Table to hold the user information
DataTable dtUserTable = new DataTable(); //Create DataTable
DataRow drUserRow;
//Add columns to DataGrid
dtUserTable.Columns.Add(new DataColumn("UserName", typeof(string)));
dtUserTable.Columns.Add(new DataColumn("Email", typeof(string)));
dtUserTable.Columns.Add(new DataColumn("IsSiteAdmin", typeof(string)));
Following code is through the user collection and access a user at a time
foreach(SPUser user in users)
{
drUserRow = dtUserTable.NewRow(); //Create DataRow
drUserRow[0] = user.Name; //Add the users name
drUserRow[1] = user.Email; //Add the users Emal
//Is a user is a site administrator
drUserRow[2] = user.IsSiteAdmin.ToString();
// Add the DataRow to the DataTable
dtUserTable.Rows.Add(drUserRow);
}
// Add the data source to the DataGrid
DGUsers.DataSource = dtUserTable;
//Bind the DataGrid
DGUsers.DataBind();
AlternateHeader Property
//Gets or sets the URL for an alternate .aspx page to use for rendering the top navigation area in SharePoint pages.
LbAlternateHeaderData.Text = site.AlternateHeader;
AnonymousState Property
This property returns a WebAnonymousState object.
//Gets or sets the level of access for anonymous users on the site.
Microsoft.SharePoint.SPWeb.WebAnonymousState AnonymousState = site.AnonymousState;
LbLevelOfAccessData.Text = AnonymousState.ToString();
Get the WebAnonymousState object value and convert to string and apply it to the label control.
AuthenticationMode Property
This property returns an AuthenticationMode object.
//Gets a value indicating that Windows authentication is the default authentication mode.
System.Web.Configuration.AuthenticationMode AuthenticationMode = site.AuthenticationMode;
LbAuthenticationModeData.Text = AuthenticationMode.ToString();
Get the AuthenticationMode object value and convert to string and apply it to the label control.
Author Property
This property returns a SPUser object.
//Gets a user object representing the user who created the Web site.
Microsoft.SharePoint.SPUser SiteAuthor = site.Author;
LbAuthorData.Text = SiteAuthor.ToString();
Get the SPUser object value and convert to string and apply it to the label control.
Description Property
//Gets or sets the description for the site.
LbSiteDescriptionData.Text = site.Description;
EmailInsertsEnabled Property
//Gets a Boolean value that indicates whether document libraries on the virtual server can accept e-mail attachments from public folders.
LbEmailAttachmentsData.Text = site.EmailInsertsEnabled.ToString();
EventHandlersEnabled Property
//Gets a Boolean value that indicates whether event handlers can be used in the site.
LbEventHandlersEnabledData.Text = site.EventHandlersEnabled.ToString();
HasUniquePerm Property
//Gets or sets a Boolean value that specifies whether the site has unique permissions.
LbUniquePermissionsData.Text = site.HasUniquePerm.ToString();
ID Property
This property returns a GUID object.
//Gets the GUID for the site.
System.Guid GuidID = site.ID;
LbSiteGUIDData.Text = GuidID.ToString();
IsADAccountCreationMode Property
//Gets a Boolean value that indicates whether user accounts are automatically created in Active Directory directory service when users are invited to the Web site.
LbADUsersData.Text = site.IsADAccountCreationMode.ToString();
IsADEmailEnabled Property
//Gets a Boolean value that indicates whether Active Directory e-mail is enabled on the site.
LbADEmailData.Text = site.IsADEmailEnabled.ToString();
IsRootWeb Property
//Gets a Boolean value that indicates whether the site is the top-level Web site of the site collection.
LbTopLevelSiteData.Text = site.IsRootWeb.ToString();
Language Property
//Gets the LCID for the language used on the site.
LbLanguageIDData.Text = site.Language.ToString();
Name Property
//Gets the name of the Web site.
LbNameData.Text = site.Name;
ParentWeb Property
This property returns a SPWeb object.
//Gets the parent Web site for the site.
Microsoft.SharePoint.SPWeb parentWeb = site.ParentWeb;
LbParentWebData.Text = parentWeb.Name;
PortalMember Property
//Gets a Boolean value that indicates whether the Web site is a member of a portal.
LbPortalMemberData.Text = site.PortalMember.ToString();
PortalName Property
//Gets the name of a portal used with the site.
LbPortalNameData.Text = site.PortalName;
PortalUrl Property
//Gets the URL to a portal used with the site.
LbPortalUrlData.Text = site.PortalUrl;
Theme Property
//Gets the name of the theme that is applied to the Web site.
LbThemeData.Text = site.Theme;
ThemeCssUrl Property
//Gets the URL for the cascading style sheets file used in the
//theme for the Web site.
LbThemeURLData.Text = site.ThemeCssUrl;
Title Property
//Gets the title for the Web site.
LbTitleData.Text = site.Title;
Url Property
//Gets the absolute URL for the Web site.
LbURLData.Text = site.Url;