File copy in asp

J

JP SIngh

Hi All

I want to use ASP to copy a file from one folder to another.

I am using the following code but it gives me a file not found error on the
destination file name. All is want is

1. The user chooses the name of the template from a dropdown.
2. I want to take the template file that the user has choosen
3. Give it a newname ie. strContractId & strTemplateName
4. Copy the file to a new folder with the new name.

<%
strTemplateName = request.form("contemplate")
strContractId = request.form("contractId")

strfileName = strTemplateName
strDestFileName = strContractId & strTemplateName

strOrgPath = "c:\InetPub\wwwroot\mypro\templates\" & strFilename
strDestinationPath = "c:\myusername\" & strDestFileName

' * * * it works if I explicity define the file name like it works but if i
want to create the destination file using the variable like the line above
it fails.
' What is that I am doing wrong.

strDestinationPath = "c:\" & "metext.txt"

' Example code 1
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile strOrgPath, strDestinationPath

' Example code 2
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.GetFile(strOrgPath )
f.Copy strDestinationPath ,false
set f=nothing
set fs=nothing
%>
 
E

Evertjan.

JP SIngh wrote on 22 aug 2005 in
microsoft.public.inetserver.asp.general:
strOrgPath = "c:\InetPub\wwwroot\mypro\templates\" & strFilename
strDestinationPath = "c:\myusername\" & strDestFileName

' * * * it works if I explicity define the file name like it works but
if i want to create the destination file using the variable like the
line above it fails.
' What is that I am doing wrong.

No write rights on the destination directory?
 
B

Bullschmidt

Perhaps try changing this:
strDestinationPath = "c:\" & "metext.txt"

To be more like this instead (i.e. not stating a filename):
strDestinationPath = "c:\"

And here's a related resource:
CopyFile Method
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script5
6/html/jsmthcopyfile.asp

Best regards,
J. Paul Schmidt, Freelance ASP Web Developer
http://www.Bullschmidt.com
ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...

<<
I want to use ASP to copy a file from one folder to another.

I am using the following code but it gives me a file not found error on
the
destination file name. All is want is

1. The user chooses the name of the template from a dropdown.
2. I want to take the template file that the user has choosen
3. Give it a newname ie. strContractId & strTemplateName
4. Copy the file to a new folder with the new name.

<%
strTemplateName = request.form("contemplate")
strContractId = request.form("contractId")

strfileName = strTemplateName
strDestFileName = strContractId & strTemplateName

strOrgPath = "c:\InetPub\wwwroot\mypro\templates\" & strFilename
strDestinationPath = "c:\myusername\" & strDestFileName

' * * * it works if I explicity define the file name like it works but
if i
want to create the destination file using the variable like the line
above
it fails.
' What is that I am doing wrong.

strDestinationPath = "c:\" & "metext.txt"

' Example code 1
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile strOrgPath, strDestinationPath

' Example code 2
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.GetFile(strOrgPath )
f.Copy strDestinationPath ,false
set f=nothing
set fs=nothing
%>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top