Add(String, Byte[], Microsoft.SharePoint.SPUser, Microsoft.SharePoint.SPUser, System.DateTime, System.DateTime) Method
The Add method of the SPFileCollection class 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.
Parameters
strUrl A string that specifies the URL for the file.
file A byte array containing the file.
createdBy A Microsoft.SharePoint.SPUser object that represents the user who created the file.
modifiedBy A Microsoft.SharePoint.SPUser object that represents the user who last modified the file.
timeCreated A System.DateTime value that specifies when the file was created.
timeLastModified A System.DateTime value that specifies when the file was last modified.
Return Value
A Microsoft.SharePoint.SPFile object that represents the file.
Remarks
This method fails to overwrite a file if the file already exists. If the user running the command is not a member of the Administrator site group, the SPUser and DateTime parameters do not apply.
This Add method works on a Site Document Library, however, if you use it with an Area Document library, the call will fail with an "Access Denied" error. However, if you do not include the last 4 parameters in the Add method, the file will be added to the Area Document library, but you will not be able to change the Author and document times.
Example
The following code example copies each of the files in the top folder of a document library in one site to the document library of another site.
This example requires using directives (Imports in Visual Basic) for both the Microsoft.SharePoint and Microsoft.SharePoint.WebControls namespaces.
Requirements
Platforms: Microsoft Windows Server 2003
Security: Code Access Security