I have tried the code above the line, and below the line in the following Subroutine:
Code:
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))
f.Close()
Rsp.Buffer = True
Rsp.Clear()
Rsp.AppendHeader("Content-Disposition", "attachment; filename=" & FileName)
Rsp.AppendHeader("Content-Length", fSize)
Rsp.BinaryWrite(Buffer)
Rsp.End()
' ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
Dim f As New FileInfo(FileName)
Rsp.Buffer = True
Rsp.Clear()
Rsp.AddHeader("Content-Disposition", "attachment; filename=" & FileName)
Rsp.AddHeader("Content-Length", f.Length())
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.
End Sub
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:
Code:
File name: wfv_view
File Type:
From: localhost
â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?