SPWebCollection.Item property (Int32)

Gets the element at the specified index in the collection. In C#, this property is an indexer for the SPWebCollection class.

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

public SPWeb this[
	int i
] { get; }


Type: System.Int32

A 32-bit integer that specifies the index.

Property value

Type: Microsoft.SharePoint.SPWeb
An SPWeb object that represents the website.

The Item property throws an ArgumentOutOfRangeException if the specified index is outside the valid range of indices for the collection.

The following code example iterates through all the users of each site in a specified site collection and displays the user names of users who are members of the Administrator site group for the site collection.

This example requires using directives (Imports in Visual Basic) for the Microsoft.SharePoint and Microsoft.SharePoint.Utilities namespaces.

SPSite oSiteCollection = SPContext.Current.Site;
SPWebCollection collWebsites = oSiteCollection.AllWebs["Website_Name"].Webs;

for (int intIndexWebsites = 0; intIndexWebsites < collWebsites.Count; 
    SPUserCollection collUsers = collWebsites[intIndexWebsites].Users;
    for (int intIndexAdmins = 0; intIndexAdmins < collUsers.Count; 
        if (collUsers[intIndexAdmins].IsSiteAdmin)
              + "--" + collUsers[intIndexAdmins].LoginName + "<BR>");

Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects.