When SharePoint installed it uses an IIS web site through one-time configuration
process to enable it for hosting SharePoint sites. This type of IIS web site
is known as web application in SharePoint terminology. The SharePoint object
model has a class named SPWebApplication that we can use to program against web
applications from managed code.
Following is the list of properties exposed by SPWebApplication class:
AllowAccessToWebPartCatalog: This boolean property specifies wheter the sites and sub sites in the web application
can use Web Parts from the global Web part catalog.
AllowPartToPartCommunication: This boolean property indicates that wheter the web parts on the page can communicate
with each other or not.
ApplicationPool: This property represents the SPApplicationPool object, which represents the associated
application pool of the web appliation.
BlockedFileExtensions: This string collection property contains the list of file extensions which are
blocked for the web application for being uploaded to the sites in web application
or downloaded from the same.
ContentDatabases: This gets the SPConnectionDatabaseCollection collection that contains the SPContentDatabase
objects, which represent content databases associated with web application.
DaysToShowNewInstance: This integer value property specifies how many days the New icon is displayed next
to the new created items or documents.
DefaultTimeZone: This gets or sets the default time zone for the web application. This is an integer
type property.
DisplayName; This represents the display name of the web application.
Farm: The SPFarm object is represented by this property, which refers the hosting farm
of the web application.
Features: This collection property of type SPFeatureCollection, provides information about
the features activated for the web application.
Id: The GUID uniquely identifies the web application.
IsAdministrationWebApplication: This property identifies that the current web application is the SharePoint Central
Administration application or not.
Name: This property represents the name of the web application.
Properties: This gets the property bag which is used to store and retrieve properties for the
web application. Values are stored and retrieved from this property bag is done
by SharePoint automatically.
Sites: This provies the list of sites in the web application.
Status: This tell about the current status of the web application. This property is of
SPObjectStatus enumeration type and its possible vlaues are Disabled, Offline,
Online, Provisioning, Unprovisioning and Upgrading.
WebService: List of web services represented by SPWebService object is presented by this property.
The following is the list of public methods exposed by SPWebApplication class, which are used in managed code:
Delete: This method deletes the web application.
GrantAccessToProcessIdentity: Access to the process identity of web application is granted to a particular user
by using thie method. Thie method basically granst full access to the web application.
Lookup: This method gets the reference to the SPWebApplication object, based on provided
URL as parameter.
Provision: This method provisions (creates) the web application on the local sever.
Unprovision: This method unprovisions (removes) the web application from all local IIS web sites.
Update: This saves all the changes to all web servers in the server farm for particular
web application by serializing the changes.
UpdateCredentials: This method commits new credentials to the database for given web application.
UpdateMailSettings: This method saves the new email settings which are used to send emails to the required
users.
Following code sample gives you an idea how you can use this SPWebApplication object
in managed code:
using System;
using Microsoft.SharePoint.Administration;
namespace ClassLibrary1
{
public class Program
{
public static void Main(string[] args)
{
SPWebServiceCollection serviceCollection = new SPWebServiceCollection(SPFarm.Local);
foreach (SPWebService service in serviceCollection)
{
SPWebApplicationCollection webApplications = service.WebApplications;
foreach (SPWebApplication application in webApplications)
{
Console.WriteLine("Name: {0}", application.Name);
Console.WriteLine(" Allow access to web part catalog: {0}", application.AllowAccessToWebPartCatalog);
Console.WriteLine(" Allow web parts to communicate: {0}", application.AllowPartToPartCommunication);
Console.WriteLine(" Application pool name: {0}", application.ApplicationPool.Name);
Console.WriteLine(" Days to show new icon: {0}", application.DaysToShowNewIndicator);
Console.WriteLine("------------------------------------");
}
}
}
}
}