Writing to header (forcing downloads)

Results 1 to 3 of 3

Thread: Writing to header (forcing downloads)

  1. #1
    Join Date
    Dec 1969

    Default Writing to header (forcing downloads)

    I have successfully created a page that dynamically gets the ContentType (which I&#039;m now reading is not always necessary). I have it so the href for my files calls the download page with the filename (e.g. download.asp?file=abc.txt), this works well because it is a popup and the first page can remain unchanged. My problem is the popup page never goes away, I have tried adding some JavaScript to close the window, but the HTML never gets written to the page at all and is instead replaced by HTML created by the server. <BR><BR>Does anyone know how I can get this popup page to close?<BR>

  2. #2
    Join Date
    Dec 1969
    Los Angeles, CA

    Default Make life easy

    why call another page and pass the file name....why not just hav eyour HREF link to the file abc.txt?/<BR><BR><BR>

  3. #3
    Join Date
    Dec 1969

    Default RE: Make life easy

    I presume you are using ADO.Stream and doing Response.BinaryWrite<BR><BR>If you do something like<BR><BR>&#060;%<BR>Response.Buffer = True<BR>Response.Clear<BR><BR>&#039;Update the DataBase here to Log the DownLoad.<BR><BR><BR>strFileName = Request.QueryString("file")<BR>strFileType = Request.QueryString("type")<BR>&#039;All of these should work<BR>&#039;if strFileType = "" then strFileType = "bad/type"<BR>&#039;if strFileType = "" then strFileType = "application/octet-stream"<BR>if strFileType = "" then strFileType = "application/download"<BR>strFile = Right(strFileName, Len(strFileName) - InStrRev(strFileName,"\"))<BR><BR>Response.Content Type = strFileType<BR>Response.AddHeader "Content-Disposition", "attachment; filename=""" & strFile &""""<BR><BR>Set Stream = Server.CreateObject("ADODB.Stream")<BR>Stream.Open <BR>Stream.LoadFromFile strFileName<BR>Contents = Stream.ReadText<BR>Response.BinaryWrite Contents<BR>Stream.Close<BR>Set Stream = Nothing<BR><BR>Response.End<BR>%&#062;<BR><BR>I think the browser window closes itself, if I remember correctly??<BR><BR>Otherwise, before Response.End, Just write some JS into the browser to close it!<BR>

Posting Permissions

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