Copy (UploadedFile Object)
Call this method to copy files which have been saved to disk to a specified
destination on the server.
Syntax
UploadedFileObject.Copy (Destination As String [, Overwrite As Bool = FALSE])
The Copy method
syntax has the following parts:
Part |
Description |
Destination |
The full pathname of the destination (including the filename). |
Overwrite |
If this is TRUE then an existing file with the same filename will be overwritten. Defaults to FALSE |
Remarks
An exception is thrown if the operation fails. Trap for success/failure by examining VBScript's Err object immediately after calling this method (the Number property of the Err object will be a non-zero value if it failed). MAKE SURE that you have enabled inline error trapping by using an On Error Resume Next statement at the beginning of the ASP page.
An exception will be thrown if you attempt to copy a file if the Files collection was populated using the SaveToMemory method. If files are saved using a virtual path (i.e. the UseVirtualDir property has been set to TRUE) then a virtual path should also be used for the Destination argument.
When calling this method you must specify the directory and filename for the desired destination (e.g. "e:\temp\myfile.txt"). To copy the file to a directory using the same name that the file was saved to disk with you can use the Upload control's GetFileName method, using the UploadedFile object's Path property as the argument. See the sample source code below for an illustration of this.
See Also: Move | Delete | Save
Example
'we will assume that the Files collection has been populated using the Upload
' control's Save method (e.g. uploaded files have been saved to disk).
'
'this sample code copies the files saved to disk to a directory named "temp",
' using the filenames that the files were saved to disk with.
'create instance of control
Set objUpload = Server.CreateObject("Dundas.Upload.2")
'populate collections and retrieve all uploaded form data (including
' uploaded files)
objUpload.Save "c:\SomeDir"
'loop through all uploaded files and copy each file to the "temp"
' directory, using the same filenames that the files were saved
' to disk with.
For Each objUploadedFile in objUpload.Files
objUploadedFile.Copy "c:\temp\" & objUpload.GetFileName(objUploadedFile.Path)
Next
'release resources
Set objUpload = Nothing