获取集合中指定索引处的文件夹对象。在 C# 中,此属性是SPFolderCollection类的索引器。
命名空间: Microsoft.SharePoint
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
Public ReadOnly Default Property Item ( _
iIndex As Integer _
) As SPFolder
Get
用法
Dim instance As SPFolderCollection
Dim iIndex As Integer
Dim value As SPFolder
value = instance(iIndex)
public SPFolder this[
int iIndex
] { get; }
参数
iIndex
类型:System.Int3232 位整数,它指定该文件夹的索引。
属性值
类型:Microsoft.SharePoint.SPFolder
SPFolder 对象,该对象代表的文件夹。
备注
如果指定的索引的索引集合的有效范围, Item属性将引发ArgumentOutOfRangeException 。
示例
下面的代码示例使用索引器在网站中显示的名称和每个文件夹的文件数。
此示例要求using指令 (在 Visual Basic 中的Imports ) 的Microsoft.SharePoint和Microsoft.SharePoint.Utilities的命名空间。
Dim site As SPWeb = SPControl.GetContextWeb(Context)
Dim folders As SPFolderCollection = site.Folders
Dim i As Integer
For i = 0 To folders.Count - 1
Label1.Text += SPEncode.HtmlEncode(folders(i).Name) & " :: " &
folders(i).Files.Count.ToString() & "<BR>"
Next i
SPWeb oWebsite = SPContext.Current.Web;
SPFolderCollection collFolders= oWebsite.Folders;
for (int intIndex=0; intIndex<collFolders.Count; intIndex++)
{
Label1.Text += SPEncode.HtmlEncode(collFolders[intIndex].Name)
+ " -- " +
collFolders[intIndex].Files.Count.ToString() + "<BR>";
}