Results 1 to 5 of 5

Thread: Copy File to LocalHost [RESOLVED]

  1. #1

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Copy File to LocalHost [RESOLVED]

    I need to copy a file, on the web server, to the web page directory so it can be made available to download from the web page.

    However, I need to do it in code. How do I findout the path to the web page folder in the localhost so that I can use the FileCopy command?
    Last edited by simonm; Mar 11th, 2005 at 08:17 AM.
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  2. #2
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: Copy File to LocalHost

    You need to add a HtmlInputFile control onto a page to upload the file to the server.
    Code:
    void Upload_Click(Object sender, EventArgs e) {
    	if (fileUp.PostedFile.ContentLength > 0) {
    		fileUp.PostedFile.SaveAs("C:\uploadedFiles" + fileUp.PostedFile.FileName);
    	}
    }
    
    <input type="file" id="fileUp" runat="server" />
    <asp:Button id="upload" runat="server" OnClick="Upload_Click" />
    Obviously you can change the path to the directory you want to save to.

    HTH

    DJ

  3. #3

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Re: Copy File to LocalHost

    No, the file I want is already on the server.

    Anyway, my problem is resolved now.
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  4. #4
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: Copy File to LocalHost [RESOLVED]

    Sorry your description seemed to indicate you wanted to copy a file from localhost to the server.

    If you have a chance post the solution you found so if anyone searches for a similar subject in the future the answer is here - I'm also interested to see what you were doing

    Cheers

    DJ

  5. #5

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Re: Copy File to LocalHost [RESOLVED]

    VB Code:
    1. Server.MapPath()
    Returns the directory on the web server that contains my web page application.

    Using this, I was able to copy a file from my "Temp" directory to my webhost directory like this:
    VB Code:
    1. strFileName = "Text.txt"
    2. strTargetDirectory = Server.MapPath(strFileName)
    3. FileSystem.FileCopy("C:\Temp\" & strFileName, strTargetDirectory)
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

Posting Permissions

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



Click Here to Expand Forum to Full Width