共用方式為


SPWebCollection.Item property (Int32)

取得集合中的指定索引處的項目。在 C# 中,這個屬性會是SPWebCollection類別的索引器。

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

Syntax

'宣告
Public ReadOnly Default Property Item ( _
    i As Integer _
) As SPWeb
    Get
'用途
Dim instance As SPWebCollection
Dim i As Integer
Dim value As SPWeb

value = instance(i)
public SPWeb this[
    int i
] { get; }

參數

Property value

Type: Microsoft.SharePoint.SPWeb
代表網站的SPWeb物件。

備註

如果指定的索引超出集合的索引的有效範圍,則Item屬性會擲回ArgumentOutOfRangeException 。

Examples

下列程式碼範例會逐一查看所有使用者的指定的網站集合中每個網站,並顯示網站集合管理員網站群組的成員使用者的使用者名稱。

這個範例需要Microsoft.SharePointMicrosoft.SharePoint.Utilities命名空間using指示詞 (在 Visual Basic 中的Imports )。

Dim siteCollection As SPSite = SPContext.Current.Site
Dim webSites As SPWebCollection = siteCollection.AllWebs("Site_Name").Webs
Dim i As Integer

For i = 0 To webSites.Count - 1

    Dim users As SPUserCollection = webSites(i).Users
    Dim j As Integer

    For j = 0 To users.Count - 1

        If users(j).IsSiteAdmin Then

            Response.Write(SPEncode.HtmlEncode(webSites(i).Title) & " :: " 
                & users(j).LoginName & "<BR>")

        End If

    Next j

    collWebsites(intIndexWebsites).Dispose()
Next i
SPSite oSiteCollection = SPContext.Current.Site;
SPWebCollection collWebsites = oSiteCollection.AllWebs["Website_Name"].Webs;

for (int intIndexWebsites = 0; intIndexWebsites < collWebsites.Count; 
     intIndexWebsites++)
{
    SPUserCollection collUsers = collWebsites[intIndexWebsites].Users;
    for (int intIndexAdmins = 0; intIndexAdmins < collUsers.Count; 
         intIndexAdmins++)
    {
        if (collUsers[intIndexAdmins].IsSiteAdmin)
        {
            Response.Write(SPEncode.HtmlEncode(collWebsites[intIndexWebsites].Title) 
              + "--" + collUsers[intIndexAdmins].LoginName + "<BR>");
        }
    }
    collWebsites[intIndexWebsites].Dispose();
}
注意事項注意事項

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.

請參閱

參照

SPWebCollection class

SPWebCollection members

Item overload

Microsoft.SharePoint namespace