1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Rep Power

    Classic ASP - Need help with download text file

    This is my second attempt at answering this question. The previous attempt which was closed by Doug G for an unknown reason. All I am trying to do is find out how to accomplish this. I received one answer that had a link to a site in another language.

    Hi all,

    I am creating a text file, that once created is to be downloaded. I have the file being created and saved on the server, the problem I am having is getting the download/open dialog to work. The following is my current code and while this works to a point, the file the user receives is a text file containing html code along with the contents of the actual file.

    Any and all help is appreciated.

    Const adTypeBinary = 1
    dim strFileName
    strFileName = "test.txt"
    dim strFilePath
    strFilePath = "c:\extracts\" + strFileName

    dim objStream
    Set objStream = Server.CreateObject("ADODB.Stream")
    objStream.Type = adTypeBinary
    objStream.LoadFromFile strFilePath

    Response.AddHeader "Content-Disposition", "attachment; filename=" & strFileName
    Response.Charset = "UTF-8"
    Response.ContentType = "image/jpeg"

    Response.BinaryWrite objStream.Read
  2. #2
  3. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Rep Power
    What have you done to attempt to debug this code? I don't know the ado strream object, sorry.

    I closed the other post because of the useless adfly references
    Doug G
    I've never been able to appreciate the sublime arrogance of folks who feel they were put on earth just to save other folks from themselves .." - Donald Hamilton

IMN logo majestic logo threadwatch logo seochat tools logo