Results 1 to 6 of 6

Thread: Copy a file

  1. #1
    Join Date
    Oct 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Copy a file

    Hi,

    My goal is to duplicate (copy) a file already in the root of my website. i.e. copy www.mysite.com/file.txt to www.mysite.com/newfile.txt

    It works fine on my PC (VWD environment) but get an error when I try to execute the code on the server.

    the code is the following:

    Dim fs
    fs = CreateObject("Scripting.FileSystemObject")
    fs.CopyFile(Server.MapPath("File.txt"), Server.MapPath("newFile.txt"))


    Can you help? Many thanks in advance, and Happy New Year to everyone!

    Pascal

  2. #2
    Join Date
    Mar 2005
    Location
    Isle of Man
    Posts
    1,261
    Thanks
    3
    Thanked 24 Times in 24 Posts

    Default

    You could do it with PHP like this:
    PHP Code:
    copy('file.txt','newfile.txt'); 

  3. #3
    Join Date
    Oct 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Yes but I am using ASP.NET

    thanks Nick for your help. I do not know if I can mix PHP and ASP.NET? But I do not thing it is a language issue anyway, because it works on my PC.

  4. #4
    Join Date
    Mar 2005
    Location
    Hampshire
    Posts
    432
    Thanks
    4
    Thanked 3 Times in 3 Posts

    Default

    Quote Originally Posted by PascalUK View Post
    Hi,

    Dim fs
    fs = CreateObject("Scripting.FileSystemObject")
    fs.CopyFile(Server.MapPath("File.txt"), Server.MapPath("newFile.txt"))
    Note that this is ASP not ASP.Net code that you are using. Under Medium Trust you are not allowed to create ActiveX objects (if my memory serves me).

    Try this code
    Code:
    Try
    Dim sourceFile AsString = Server.MapPath("test.txt")
    Dim destinationFile AsString = Server.MapPath("tester" & DateTime.Now.ToString("MMddyyy") & ".txt")
    System.IO.File.Copy(sourceFile, destinationFile)
    Catch Ex As Exception
    Response.Write(Ex.Message)
    EndTry
    
    I have tested this in my test enviroment and it works in Medium Trust, and I'm using .Net2

    Hope it helps

    Just chill

  5. #5
    Join Date
    Oct 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Fixed!

    Thank you Tanzy for your answer it works!

  6. #6
    Join Date
    Mar 2005
    Location
    Hampshire
    Posts
    432
    Thanks
    4
    Thanked 3 Times in 3 Posts

    Default

    No problem, you have to be careful when you look for ASP.net code, make sure that you don't get confused with Classic ASP (aka ASP 3). With ASP.Net you can code in 2 languages vb.net or C#

    Just chill

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Blocked file extensions
    By steve_green in forum Technical Support
    Replies: 2
    Last Post: 22nd October 2006, 02:49 PM
  2. How to copy a MySql database ?
    By JohnHorne in forum MySQL
    Replies: 4
    Last Post: 6th November 2005, 12:31 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •