获取位于集合中指定的 URL 的文件夹对象。在 C# 中,此属性是SPFolderCollection类的索引器。
命名空间: Microsoft.SharePoint
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
Public ReadOnly Default Property Item ( _
urlOfFolder As String _
) As SPFolder
Get
用法
Dim instance As SPFolderCollection
Dim urlOfFolder As String
Dim value As SPFolder
value = instance(urlOfFolder)
public SPFolder this[
string urlOfFolder
] { get; }
参数
urlOfFolder
类型:System.String一个包含 URL 的字符串。
属性值
类型:Microsoft.SharePoint.SPFolder
SPFolder 对象,该对象代表的文件夹。
示例
下面的代码示例使用索引器可以在指定的文件夹中显示的名称和每个文件的长度。
此示例要求using指令 (在 Visual Basic 中的Imports ) 的Microsoft.SharePoint和Microsoft.SharePoint.Utilities的命名空间。
Dim site As SPWeb = SPControl.GetContextWeb(Context)
Dim folder As SPFolder = site.Folders("Shared Documents")
Dim file As SPFile
For Each file In folder.Files
Label1.Text += folder.Url & " :: " &
SPEncode.HtmlEncode(file.Name) &
" :: " & file.Length.ToString() & "<BR>"
Next file
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>";
}