I prefer a different method for sending files. It works for me with all kinds of different types and sizes of files.
Instead of using Response.Redirect, allow the link to the file to do a postback where you modify the response, like so:
Public Shared Sub SendFileToBrowser(ByRef response As HttpResponse, ByVal filepath As String, Optional ByVal filename As String = "", Optional ByVal contentType As String = "", Optional ByVal disposition As String = "", Optional ByVal contentLength As String = "")
Dim ext As String = filepath.Substring(filepath.Length - 3, 3)
If String.IsNullOrEmpty(contentType) Then
If ext = "pdf" Then
contentType = "application/pdf"
Else
contentType = "application/file"
End If
End If
If String.IsNullOrEmpty(disposition) Then
disposition = "attachment"
End If
If String.IsNullOrEmpty(filename) Then
''//Test for relative url path
Dim fileparts As String() = filepath.Split("/")
If fileparts.Length > 1 Then
filename = fileparts(fileparts.Length - 1)
Else
''//Test for absolute file path
Dim fileparts2 As String() = filepath.Split("\") ''//" SO: Fix syntax highlighting
If fileparts2.Length > 1 Then
filename = fileparts2(fileparts2.Length - 1)
Else
''//Just give it a temp name
filename = "temp." & ext
End If
End If
End If
response.Clear()
response.AddHeader("content-disposition", disposition & ";filename=" & filename)
If Not String.IsNullOrEmpty(contentLength) Then
response.AddHeader("Content-Length", contentLength)
End If
response.ContentType = contentType
response.Cache.SetCacheability(HttpCacheability.Public)
response.TransmitFile(filepath)
response.End()
End Sub
Note: Using "''//" for comments so that the syntax highlighter works properly. This still compiles properly as well.
This works for us in IE6 and IE7.