SPFolderCollection class
表示SPFolder物件的集合。
Inheritance hierarchy
System.Object
Microsoft.SharePoint.Administration.SPAutoSerializingObject
Microsoft.SharePoint.SPBaseCollection
Microsoft.SharePoint.SPFolderCollection
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Public Class SPFolderCollection _
Inherits SPBaseCollection
'用途
Dim instance As SPFolderCollection
public class SPFolderCollection : SPBaseCollection
備註
使用SPWeb類別的Folders屬性或Subfolders()SPFolder類別屬性,傳回的網站或資料夾的資料夾集合。若要建立資料夾,請使用SPFolderCollection的Add方法。
若要從集合傳回單一資料夾中使用索引子。例如,假設集合指派給變數,名為collFolders,使用在 C# 的collFolders[index]或 Visual Basic,其中index是集合中資料夾的索引編號,或者是顯示名稱的資料夾中的collFolders(index) 。
Examples
下列程式碼範例將複製共享文件的文件庫,排除 [表單] 子資料夾中,到在相同的站台上的另一個文件庫的所有子的資料夾。
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。 |
Thread safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.