I have tried the code above the line, and below the line in the following Subroutine:
Public Sub DownLoadResults(ByVal FileName As String, ByVal Rsp As HttpResponse)
Dim f As New FileStream(FileName, FileMode.Open)
Dim fSize As Long = f.Length
Dim Buffer(CInt(fSize)) As Byte
f.Read(Buffer, 0, CInt(fSize))
Rsp.Buffer = True
Rsp.AppendHeader("Content-Disposition", "attachment; filename=" & FileName)
Dim f As New FileInfo(FileName)
Rsp.Buffer = True
Rsp.AddHeader("Content-Disposition", "attachment; filename=" & FileName)
Rsp.ContentType = "text/plain" ' Set the appropriate ContentType.
Rsp.Charset = "UTF-8"
Rsp.WriteFile(FileName) ' Write the file directly to the
Rsp.End() ' HTTP output stream.
Both versions operate identically. (I switched to the first version—the part above the line—after getting undesirable results with the second version—the part below the line.)
In both cases, in the Save/Open/Cancel dialog that is presented for downloading the file, the message is:
File name: wfv_view
“wfv_view” is the name of the .aspx page with the download link on it.
The link’s href is “http : // localhost/WF/wfv_view.aspx?Action=DownLoad” (but without the spaces...) The name of the file in FileName is like Temp002.txt, Temp003.txt, etc.
When I select to save the file, the “Save as [u]t</u>ype:” textbox says “HTML Document.”
If I change the file name to (for instance) Tmp.txt
, what gets saved is Tmp.txt.aspx
. I need to specify "Tmp.txt"
(delineate with quotes) to get a file extension other than .aspx. In any event, the actual file itself—the contents, that is—gets saved properly.
This is [u]not</u> the results I had with very similar code in VB6.
How can I get the downloading functionality between .NET and Internet Explorer to present a “Save” dialog box with the actual filename, and with the appropriate extension type preselected?