For Programmers: Free Programming Magazines  


Home > Archive > ASP > August 2005 > File copy in asp









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author File copy in asp
JP SIngh

2005-08-22, 7:55 am

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
%>


Evertjan.

2005-08-22, 6:56 pm

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?

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Bullschmidt

2005-08-22, 6:56 pm

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/d...y/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
%>[color=darkred]

*** Sent via Developersdex http://www.developersdex.com ***
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com