共用方式為


SPFileCollection class

表示SPFile物件的集合。

Inheritance hierarchy

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

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'宣告
Public Class SPFileCollection _
    Inherits SPBaseCollection
'用途
Dim instance As SPFileCollection
public class SPFileCollection : SPBaseCollection

備註

使用的SPWebSPFolder類別的Files屬性,傳回的網站或資料夾的檔案集合。若要建立新的檔案,使用其中一個SPFileCollection的Add方法。

若要從集合傳回單一檔案中使用索引子。例如,假設集合指派給變數,名為collFiles,使用在 C# 的collFiles[index]或 Visual Basic,其中index是集合中檔案的索引號碼,或者是顯示名稱的檔案中的collFiles(index) 。

Examples

下列程式碼範例會檢查指定的文件庫的最上層資料夾中的每個檔案的上次修改它,如果時間小於某個值,會將檔案複製到另一個文件庫。

Dim SiteCollection As New SPSite("http://MySiteCollection")
Try
    Dim srcFolder As SPFolder = siteCollection.AllWebs("SourceWebSite").GetFolder("SourceDocLib")
    Dim destFiles As SPFileCollection = siteCollection.AllWebs("DestWebSite").GetFolder("DestDocLib").Files

    Dim srcFile As SPFile
    For Each srcFile In  srcFolder.Files
        If srcFile.TimeLastModified < Convert.ToDateTime("12/5/2002 12:00:00 AM") Then
            Dim destURL As String = destFiles.Folder.Url + "/" + srcFile.Name
            Dim binFile As Byte() = srcFile.OpenBinary()

            destFiles.Add(destURL, binFile, True)
        End If
    Next srcFile
Finally
    SiteCollection.Dispose()
End Try
using (SPSite oSiteCollection = new SPSite("http://MySiteCollection"))
{
    SPWeb oSourceWebsite = oSiteCollection.AllWebs["SourceWebSite"];
    SPWeb oDestinationWebsite = oSiteCollection.AllWebs["DestWebSite"];

    SPFolder oFolder = oSourceWebsite.GetFolder("SourceDocLib");
    SPFileCollection collFiles = oDestinationWebsite.GetFolder("DestDocLib").Files;

    foreach (SPFile oFile in oFolder.Files)
    {
        if (oFile.TimeLastModified < Convert.ToDateTime("12/7/2007 12:00:00 AM"))
        {
            string strDestURL = collFiles.Folder.Url + "/" + oFile.Name;
            byte[] binFile = oFile.OpenBinary();

            collFiles.Add(strDestURL, binFile, true);
        }
    }
    oSourceWebsite.Dispose();
    oDestinationWebsite.Dispose();
}
注意事項注意事項

某些物件實作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.

請參閱

參照

SPFileCollection members

Microsoft.SharePoint namespace