Results 1 to 6 of 6

Thread: Load files

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Load files

    Hi,

    Im new to asp.net.I need to load several files from a web site.
    My type of files are ppt, doc, xls files. I have made a search on the forum and thanks to Menhdak I found this

    VB Code:
    1. if System.IO.File.Exists(Server.MapPath("createdfiles/woof.txt")) Then
    2.  
    3.         Dim TargetFile As New System.IO.FileInfo(Server.MapPath("createdfiles/woof.txt"))
    4.  
    5.         ' clear the current output content from the buffer
    6.         Response.Clear()
    7.         ' add the header that specifies the default filename for the Download/
    8.         ' SaveAs dialog
    9.         Response.AddHeader("Content-Disposition", "attachment; filename=" + _
    10.             TargetFile.Name)
    11.         ' add the header that specifies the file size, so that the browser
    12.         ' can show the download progress
    13.         Response.AddHeader("Content-Length", TargetFile.Length.ToString())
    14.         ' specify that the response is a stream that cannot be read by the
    15.         ' client and must be downloaded
    16.         Response.ContentType = "application/octet-stream"
    17.         ' send the file stream to the client
    18.         Response.WriteFile(TargetFile.FullName)
    19.         ' stop the execution of this page
    20.         Response.End()
    21.  
    22. End If

    I replaced "createdfiles/woof.txt" and put in "mytext.doc" but this does not work. At the moment my file is in the bin. Obviously later on it will be on the server. can someone please help me with this. This is the first time Im loading a webs site. Also pls tell where i put the file and how to set its path in the code. Many many thanks
    Many thanks
    Last edited by angelica; Dec 25th, 2006 at 05:40 PM.

  2. #2
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    Re: Load files

    You need to specify the path to the file. If you've just got
    Code:
    if System.IO.File.Exists(Server.MapPath("mytext.doc")) Then
    Then it will look for mytext.doc in the root folder of the web application.

    Therefore if your document is in your bin folder then you need to specify so
    Code:
    if System.IO.File.Exists(Server.MapPath("bin/mytext.doc")) Then
    However you should create a folder in your project and place the files in there just to keep everything nice and separate.

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Load files

    It's best not to place such files in a bin folder. Have a separate folder in your application's virtual directory just for your 'downloadable' files.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: Load files[resolved]

    ok, sorted out many thanks to both Fishcake and Menhak who's always there to help. cheers
    Last edited by angelica; Dec 29th, 2006 at 04:51 AM.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: Load files [RESOLVED]

    ok, sorted out many thanks to both Fishcake and Menhak who's always there to help. cheers

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Load files

    You're welcome. You're welcome. Small things, you learn.

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