Свойство SPWebCollection.Item (Int32)
Получает элемент по указанному индексу в коллекции. В C# это свойство соответствует индексатор для класса SPWebCollection .
Пространство имен: Microsoft.SharePoint
Сборка: Microsoft.SharePoint (в Microsoft.SharePoint.dll)
Синтаксис
'Декларация
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; }
Параметры
i
Тип: System.Int3232-разрядное целое число, указывающее индекс.
Значение свойства
Тип: Microsoft.SharePoint.SPWeb
Объект SPWeb , который представляет веб-сайта.
Замечания
Свойство Item создает ArgumentOutOfRangeException , если указанный индекс находится вне допустимого диапазона индексов для коллекции.
Примеры
В следующем примере кода выполняется итерация по всем пользователям каждого сайта в семействе сайтов указанного сайта и отображает имена пользователей, которые являются членами группы администраторов семейства веб-сайтов.
Этот пример требует директивы using (Imports в Visual Basic) для пространства имен Microsoft.SharePoint и Microsoft.SharePoint.Utilities .
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.