Represents a collection of SPFile objects.
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Use an indexer to return a single file from the collection. For example, assuming the collection is assigned to a variable named collFiles, use collFiles[index] in C#, or collFiles(index) in Visual Basic, where index is either the index number of the file in the collection or the display name of the file.
The following code example checks every file in the top-level folder of a specified document library for the last time that it was modified and, if the time is less than a certain value, copies the file to another document library.
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
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.