Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2003
    Posts
    2

    Question Unanswered: ASP - cant download txt file

    I have a problem. I've prepared a delimited text file of data, and want the user to be able to download it to the local machine. This is how I have done it, but it seems to open the file for viewing rather than download it:

    Click <a href='Myfile.txt'>here</a> to download.


    Help!

  2. #2
    Join Date
    Jul 2003
    Location
    Ohio/Chicago
    Posts
    75
    uh oh, did you click do not remind me again button at one time so it doesn't prompt ever?

    did you try it on a different machine besides yours?

    Did you set up the server to interpret .txt files?

  3. #3
    Join Date
    Aug 2003
    Posts
    2
    Im not sure If I clicked dont prompt ever. I may have. Which means that others probably would have too. Which makes this solution unsuitable.

    I have just tried it on 2 other machines with the same result.

    Im researching setting the server to interpret .txt files.


    Do you (or anybody) know of a better way to do it?

  4. #4
    Join Date
    Jul 2003
    Location
    SoCal
    Posts
    721
    Originally posted by BScullio
    Im not sure If I clicked dont prompt ever. I may have. Which means that others probably would have too. Which makes this solution unsuitable.

    I have just tried it on 2 other machines with the same result.

    Im researching setting the server to interpret .txt files.


    Do you (or anybody) know of a better way to do it?
    I'm assuming, since this is the ASP forum, that you can execute ASP code. The best way to FORCE them to download the file is to stream it to them through ASP:

    Code:
    <%
    Response.Buffer = True
    Response.Clear
    
    Dim strFilePath, strFileName
    
    Const adTypeBinary = 1
    
    Set objStream = Server.CreateObject("ADODB.Stream")
    
    strFilePath = Server.MapPath("/virtualpath/tofolder") & "\"
    strFileName = "mytextfile.txt"
    
    objStream.Open
    objStream.Type = adTypeBinary
    objStream.LoadFromFile strFilePath & strFileName
    
    Response.AddHeader "Content-Disposition", "attachment; filename=" & StrFileName
    Response.Charset = "UTF-8"
    Response.ContentType = "text/plain"
    'Google "Mime Types" for addtional Content Type definitions
    
    Response.BinaryWrite objStream.Read
    Response.Flush
    
    objStream.Close
    Set objStream = Nothing
    
    %>

Posting Permissions

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