Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Force Download of .txt File

Posted on 2003-11-06
3
Medium Priority
?
1,705 Views
Last Modified: 2008-02-20
I have an asp script that dynamically generates a .txt file from a database.  I want my application users to be able to call the script and be able to save the generated .txt file rather than view it.  Internet Explorer recognizes the text file and just displays it in the window.  My users have no need to view it, just download the file to import into another program.  Different file extensions don't work.  I just want IE to bring up the Open or Save dialog box when the browser points to this file.
0
Comment
Question by:probelaw
3 Comments
 
LVL 17

Expert Comment

by:dorward
ID: 9700147
0
 

Author Comment

by:probelaw
ID: 9701777
Ok...but how can I put that code into the file?  Just write it as lines in the text file?
0
 
LVL 58

Accepted Solution

by:
Gary earned 200 total points
ID: 9701974
<%
Response.Buffer = True

strFileName="ee.txt"  ' Set file name

strFilePath=server.mappath(strFilename) ' Set path of file
set fso=createobject("scripting.filesystemobject")
set f=fso.getfile(strfilepath)
strFileSize = f.size
set f=nothing: set fso=nothing
Const adTypeBinary = 1
Response.Clear
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath
strFileType = "application/text" ' change to the correct content type for your file
Response.AddHeader "Content-Disposition", "attachment; filename=" & strFileName
Response.AddHeader "Content-Length", strFileSize
Response.Charset = "UTF-8"
Response.ContentType = strFileType
Response.BinaryWrite objStream.Read
Response.Flush
objStream.Close
Set objStream = Nothing
%>
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
This article offers some helpful and general tips for safe browsing and online shopping. It offers simple and manageable procedures that help to ensure the safety of one's personal information and the security of any devices.
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…
Suggested Courses

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question