Share via


SPFileCollection Class

The SPFileCollection class represents a collection of SPFile objects.

System.Object

   Microsoft.SharePoint.SPBaseCollection

      Microsoft.SharePoint.SPFileCollection

Public Methods

The following table shows the public methods of the SPFileCollection class and a brief description of each.

Name Description
Add(String, Byte[]) Creates a file in the collection based on the specified URL and on a byte array that contains the file.
Add(String, Byte[], Boolean) Creates a file in the collection based on the specified URL and on a byte array that contains a file, overwriting any file of the same name only if overwrite is true.
Add(String, Byte[], Microsoft.SharePoint.SPUser, Microsoft.SharePoint.SPUser, System.DateTime, System.DateTime) Creates a file in the collection based on the specified URL, on a byte array that contains a file, on user objects that represent the users who created and last modified the file, and on DateTime values that specify when they did so.
Delete Deletes the file located at the specified URL.

Public Properties

The following table shows the public properties of the SPFileCollection class, the data type of each property, and a brief description of each.

Name Data Type Description
Count Int32 Gets the number of files in the collection.
Folder Microsoft.SharePoint.SPFolder Gets the parent folder of the collection.
Item(Int32) Microsoft.SharePoint.SPFile Gets the file object at the specified index in the collection.
Item(String) Microsoft.SharePoint.SPFile Gets the file object with the specified URL from the collection.
Web Microsoft.SharePoint.SPWeb Gets the site to which the collection belongs.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread safe.

Remarks

Use the Files property of either the SPWeb or SPFolder class to return the collection of files for the site or folder. To create a new file, use one of the Add methods represented in the table above.

Use an indexer to return a single file from the collection. For example, assuming the collection is assigned to a variable named myFiles, use myFiles[index] in C#, or myFiles(index) in Visual Basic .NET, where index is either the index number of the file in the collection or the display name of the file.

Example

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.

This example requires using directives (Imports in Visual Basic) for both the Microsoft.SharePoint and Microsoft.SharePoint.WebControls namespaces.

Requirements

Namespace: Microsoft.SharePoint

Platforms: Microsoft Windows Server 2003

Assembly: Windows SharePoint Services (in Microsoft.SharePoint.dll)

Security: Code Access Security