SPWebApplication class

Represents an Internet Information Services (IIS) load-balanced Web application that is installed on a server farm.

Namespace:  Microsoft.SharePoint.Administration
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public class SPWebApplication : SPPersistedUpgradableObject, 
	IBackupRestore, IMigratable

All servers that run the parent Web service (SPWebService) of the Web application must have a provisioned instance of the application. All instances of the application must be configured identically.

Various objects in the Microsoft.SharePoint.Administration namespace provide a WebApplication property through which you can access the containing Web application. Use the WebApplication property of the SPSite class to get the Web application that contains a site collection. To get the Web application of the current HTTP context, you can use SPContext.Current.Site.WebApplication.

Use the WebApplications property of the SPWebService class to return an SPWebApplicationCollection object that represents the collection of Web applications within a Web service. Use an indexer to return a single Web application from the collection. For example, if the collection is assigned to a variable named myWebApplications, use myWebApplications[index] in C#, or myWebApplications(index) in Visual Basic, where index is either the name or the GUID that identifies the Web application.

The following example uses the Lookup method to change the maximum file size and per-user alert settings for a specified Web application.

SPWebApplication oWebApplication = SPWebApplication.Lookup(new Uri("http://MyServer:989"));

oWebApplication.MaximumFileSize = 100;
oWebApplication.AlertsMaximum = 1000;


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