SPFolderCollection 类

表示SPFolder对象的集合。

继承层次结构

System.Object
  Microsoft.SharePoint.Administration.SPAutoSerializingObject
    Microsoft.SharePoint.SPBaseCollection
      Microsoft.SharePoint.SPFolderCollection

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

语法

声明
Public Class SPFolderCollection _
    Inherits SPBaseCollection
用法
Dim instance As SPFolderCollection
public class SPFolderCollection : SPBaseCollection

备注

使用SPWeb类的Folders属性,或者SPFolder类的**Subfolders()**属性返回的某个站点或文件夹的文件夹的集合。若要创建一个文件夹,请使用SPFolderCollection的Add方法。

使用索引器从集合中返回单个文件夹。例如,假定该集合分配给名为collFolders的变量,使用collFolders[index]在 C# 中或在 Visual Basic,其中index是集合中的该文件夹的索引号,或是该文件夹的显示名称collFolders(index) 。

示例

下面的代码示例会将共享文档的文档库,不窗体子文件夹,包括到另一个在同一站点上的文档库的所有子文件夹复制。

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

Dim srcFolders As SPFolderCollection = 
    site.GetFolder("Shared Documents").SubFolders
Dim destFolder As SPFolder = site.GetFolder("Destination_Folder")

Dim i As Integer

    For i = 0 To srcFolders.Count - 1

        If srcFolders(i).Name <> "Forms" Then

            srcFolders(i).CopyTo(destFolder.Url & "/" & 
                srcFolders(i).Name)

        End If

Next i
SPSite oSiteCollection = SPContext.Current.Site;
using (SPWeb oWebsite = oSiteCollection.AllWebs["Site_Name"])
{
    SPFolderCollection collFolders =
        oWebsite.GetFolder("Shared Documents").SubFolders;
    SPFolder oFolderDest = oWebsite.GetFolder("Destination_Folder");

    for (int intIndex = 0; intIndex < collFolders.Count; intIndex++)
    {
        if (collFolders[intIndex].Name != "Forms")
        {
            collFolders[intIndex].CopyTo(oFolderDest.Url + "/" +
                collFolders[intIndex].Name);
        }
    }
}

备注

某些对象实现IDisposable接口,并必须避免后不再需要保留这些对象在内存中。好的编码做法有关的信息,请参阅Disposing Objects

线程安全性

该类型的任何公共 静态 (已共享 在 Visual Basic 中) 成员都是线程安全的。不保证任何实例成员都是线程安全的。

另请参阅

引用

SPFolderCollection 成员

Microsoft.SharePoint 命名空间