Problem with Response.AddHeader in IE

Discussion in 'C#' started by sparky753, May 5, 2008.

  1. #1
    I have the following statement in my ASP page:

    <a href="DownloadFile.asp?File=<%= Server.URLEncode(myFile.Name) %>"><% Response.Write myFile.Name %></a>
    Code (markup):
    On clicking the link, the code on DownloadFile.asp uses a request.querystring to retrieve the name of the file:

    strClientFileName = Request.QueryString("File")
    	
    	Response.Write strClientFileName
    	
    	strServerFilePath = conDownloadFolder & "\" & strClientFileName
    	
    	strMIMEContentType = "text/plain"
    
    	
    	Set objFS = Server.CreateObject("Scripting.FileSystemObject")
    	Set objStream = objFS.OpenTextFile(strServerFilePath, 1)
    	strFileData = objStream.ReadAll()
    	Call objStream.Close()
    	Set objStream = Nothing
    	Set objFS = Nothing
    	
    	If Response.Buffer Then
    		Call Response.Clear
    		Response.Buffer = False
    	End If
    	
    	Response.Expires = -100
    	Response.CacheControl = "no-cache"
    	Response.ContentType = strMIMEContentType
    	Call Response.AddHeader("Pragma", "no-cache")
    		Call Response.AddHeader("Content-Disposition", "attachment; filename=" & strClientFileName)
    	
    	'this works inline
    	'Call Response.AddHeader("Content-Disposition", "inline; filename=" & strClientFileName)
    	
    	Call Response.Write(strFileData)
    	
    	Session("HttpDownload.TransferSeconds") = DateDiff("s", dtTransferStart, Now())
    Code (markup):

    When I click on the link in Firefox, the Save As/Open dialog box opens with the correct filename and if I click Save, it saves the file correctly. eg:myfile08.txt

    But when I click on one of the link in IE, it opens the Save As/Open dialog box but asks if I want to Save/Download the file
    DownloadFile_asp?File=myfile08_txt

    I am baffled. I know the correct filename is getting passed as indicated by my Response.Write strClientFileName statement at the beginning of the DownloadFile.asp page. Also, the inline option works perfectly:
    Call Response.AddHeader("Content-Disposition", "inline; filename=" & strClientFileName)
    Code (markup):
    But the attachment option only works in Firefox. IE can't seem to figure out what to do with it. Please help!!!

    Thanks...
     
    sparky753, May 5, 2008 IP