SPDocumentLibrary.GetItemsInFolder 方法

返回基于指定的视图和文件夹的文档库中的项的集合。

命名空间:  Microsoft.SharePoint
程序集:  Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)

语法

声明
Public Function GetItemsInFolder ( _
    view As SPView, _
    folder As SPFolder _
) As SPListItemCollection
用法
Dim instance As SPDocumentLibrary
Dim view As SPView
Dim folder As SPFolder
Dim returnValue As SPListItemCollection

returnValue = instance.GetItemsInFolder(view, _
    folder)
public SPListItemCollection GetItemsInFolder(
    SPView view,
    SPFolder folder
)

参数

  • folder
    类型:Microsoft.SharePoint.SPFolder

    一个表示要从中检索项目的文件夹的SPFolder对象。如果空引用(无 在 Visual Basic 中),返回的项的列表的根文件夹中。

返回值

类型:Microsoft.SharePoint.SPListItemCollection
表示文档SPListItemCollection对象。

备注

如果文档库包含一个或多个子文件夹和库本身作为folder参数传递, GetItemsInFolder方法将返回在顶级文件夹中,包括子文件夹,但不包括任何子文件夹中的项目的所有项目。

示例

下面的代码示例使用GetItemsInFolder方法返回的子文件夹中的所有项的 Id。表示包含在库中的项目的总体集合的索引的整数 Id。

Dim siteCollection As SPSite = SPControl.GetContextSite(Context)
Dim site As SPWeb = siteCollection.AllWebs("Site_Name")

Dim docLibName As String = "DocLibrary_Name"
Dim docLibFolder As SPFolder = site.Folders(docLibName)
Dim docLibInnerFolder As SPFolder = 
    docLibFolder.SubFolders("Subfolder_Name")

Dim docLib As SPDocumentLibrary = CType(site.Lists(docLibName), 
    SPDocumentLibrary)
Dim docLibView As SPView = docLib.Views("View_Name")

Dim docLibItems As SPListItemCollection = 
    docLib.GetItemsInFolder(docLibView, docLibInnerFolder)
Dim i As Integer

For i = 0 To docLibItems.Count - 1

    Label1.Text += docLibItems(i).ID.ToString() & "<BR>"

Next i 
SPSite oSiteCollection = SPContext.Current.Site;
using(SPWeb oWebsite = oSiteCollection.AllWebs["Site_Name"])
{
    string strDocLibName = "DocLibrary_Name";
    SPFolder oFolderParent = oWebsite.Folders[strDocLibName];
    SPFolder oFolderChild = oFolderParent.SubFolders["Subfolder_Name"];

    SPDocumentLibrary oDocumentLibrary = (SPDocumentLibrary)oWebsite.Lists[strDocLibName];
    SPView oView = oDocumentLibrary.Views["View_Name"];
    SPListItemCollection collListItems = oDocumentLibrary.GetItemsInFolder(oView, oFolderChild);

    for (int intIndex = 0; intIndex < collListItems.Count; intIndex++)
    {
        Label1.Text += collListItems[intIndex].ID.ToString() + "<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.

另请参阅

引用

SPDocumentLibrary 类

SPDocumentLibrary 成员

Microsoft.SharePoint 命名空间