You can copy a file in ASP using the Scripting.FileSystemObject which is built into the Windows scripting engine. I have written the following CopyFile() function that you can use to copy a file. Note that the anonymous Internet account user (usually IUSR_machinename), must have read access to the directories and file that are involved in the copy). For more info on the IUSR_machinename account be sure to read this FAQ:
'***************************************************************** 'Name : CopyFile 'Purpose : Copy file from source to destination 'Input: StrFileSource - path to file you want to copy ' StrFileDestination - path that file destination 'Output: StrError - Error Message 'Author : Ian Stallings 'Date : 09/27/00 '*****************************************************************
function CopyFile(strFileSource, strFileDestination, strError)
if strFileSource = "" OR strFileDestination = "" then strError = "Error - You must supply both a source and a destination" exit function end if
set fso = Server.CreateObject("Scripting.FileSystemObject") if Not fso.FileExists(strFileSource) then strError = "Error - Source file does not exist" exit function end if
if strError = "" then Set f2 = fso.GetFile(strFileSource) f2.Copy(strFileDestination) Set f2 = nothing end if
FAQ posted by shedao at
9/27/2000 3:14:55 PM to the
FileSystemObject category.
This FAQ has been viewed 65,249 times.
Do you have a FAQ you'd like to suggest?
Suggestions? Comments? If so, send it in!
Also, if you'd like to be a FAQ Admin (creating/editing FAQs),
let me know! If you are looking for other FAQs, be
sure to check out the 4Guys
FAQ and Commonly Asked Messageboard Questions!