Wrox Programmer Forums
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old July 7th, 2005, 10:10 AM
Friend of Wrox
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default How to Manipulate Download Dlg

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)
    Rsp.AppendHeader("Content-Length", fSize)


   ' ————————————————————————————————————————————————————————————————————————————

    Dim f As New FileInfo(FileName)

    Rsp.Buffer = True
    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:
  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?

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Manipulate Download Dlg BrianWren Pro VB.NET 2002/2003 0 July 7th, 2005 10:26 AM
How to Manipulate Download Dlg BrianWren ASP.NET 1.x and 2.0 Application Design 0 July 7th, 2005 10:23 AM
manipulate recordset k2_andy Access VBA 1 May 30th, 2004 05:46 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.