Wrox Programmer Forums
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." 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 Basics 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 June 29th, 2005, 03:08 PM
Friend of Wrox
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default How do I let a user download a text file?

In processing data specified on a page that allows the user to filter results from a database I write a tab-delimited text file of the data to a specific location on the server.
Following that, I show the data in a table to the user.
If they like what they see, I would like them to be able to download the file that was created.

I have a working app of this in VB6 / IIS, but now I want to do the same thing with VB.NET.

The code in the VB6 WebClass app was (this is a “Custom Web Item” in the WebClass designer):
Private Sub Send_File_Respond()

   On Error GoTo E

   Dim fSize As String:        fSize = GetFileSize("\\the_server\the_path\file.ext")
   Dim oStrm As ADODB.Stream:  Set oStrm = New ADODB.Stream

   Response.Buffer = True      ' Turning on buffering and clearing ensures that 
   Response.Clear              ' all of the header information will be at the
                               ' top.  Feature of IIS 4 and greater.
   oStrm.Type = adTypeBinary
   oStrm.LoadFromFile "\\the_server\the_path\file.ext"

   Response.AddHeader "Content-Disposition", "attachment; filename=file.ext"
   Response.AddHeader "Content-Length", fSize

   ' The fol. value is found in registry at: HKEY_CLASSES_ROOT\MIME\Database\Content Type
   Response.ContentType = "text/plain"
   Response.Charset = "UTF-8"

   Response.BinaryWrite oStrm.Read

   Set oStrm = Nothing

R: Exit Sub

E: Dim eN As Long:     eN = Err.Number
   Dim eD As String:   eD = Err.Description
   SetCustomMessages Session, , , _
                     "Error " & eN & "<br>" & _
                     eD & "<br>" & _
                     "in Send_File_Respond()"
   Set NextItem = z__ErrorReport
   Resume R

End Sub
How do I duplicate this behavior (puts a "Save" / "Open" dialog on top of Internet Explorer) but without the ADODB features, utilizing the resources of .NET?
Old July 1st, 2005, 04:48 AM
Friend of Wrox
Join Date: Sep 2004
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts


Old July 1st, 2005, 12:19 PM
Friend of Wrox
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts

Thanks. That was helpful.
Eventually the link you posted led me to http://support.microsoft.com/kb/307603/EN-US/, “How To Write Binary Files to the Browser Using ASP.NET and Visual Basic .NET.” (Notice that the word “Download” is not to be found in the title; the keywords for the article were “kbhowtomaster”—that’s right: just the one. I [u]never</u> would have found this article...)

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I let user download a text file? BrianWren ASP.NET 1.x and 2.0 Application Design 0 June 29th, 2005 03:35 PM
user ability to download a file elladi Classic ASP Basics 3 April 1st, 2005 07:40 AM
Why user download word file is binary when open Andraw Classic ASP Basics 5 January 17th, 2005 12:41 PM
write info from user input into a text file pkdev Classic ASP Components 1 September 20th, 2003 01:59 PM

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