Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to print items from cookie to text file 1

Status
Not open for further replies.

mpnut

MIS
Aug 27, 2003
242
0
0
I have an asp page that has multiple items listed. The user can click a submit button next to an item and that item will be added to a cookie. Then they can choose other items, and so on and so one. All of which get added to the cookie. Another frame shows the contents of that cookie (the items the user selected). What I need now, and can't figure out how to do, is to save the items that are in the cookie to a text file. Is there a way to do that? Seems like it would be simple enough, but i can't find anything on it.
 
You can use the FileSystemObject to create a text file.

Do you want to save a file on the web server or on the machine where the web browser is running?

What is your ultimate goal here with the file?
 
Thank you for the quick response. The ultimate goal is to save it to a text file on the users PC that they can then print out, email to someone, blah blah blah. I am pretty knew to this so I really appreciate the help.
 
The ultimate goal is to save it to a text file on the users PC

The thing about Active Server Pages is, well you know, it runs on the server machine... so you don't get much control over what happens on the browser machine.

You can try writing some client-side code to write the text file, but unless all uses are on Windows and browsing with Internet Explorer, the client-side code will need to be written in JavaScript.

Another issue with writing files using client-side code is that many potential users may have security settings in the browser to prevent this from happening.

If you can assume that all users want your text file and they know how and where to save it, the easiest approach might be to write the contents of the text file to the Response buffer... just like you would with dynamic HTML output from your other ASPs... except set the ContentType header and ADD a Content-Disposition header that suggests to the browser that the server response is a downloaded file... something like this:
Code:
Dim strFileName
Dim strContent

strFileName = "MyTextFile.txt"
strContent = "This sentence will be inside the file."

strContent = strContent & vbCrLf  ' carriage return / line feed

strContent = strContent & "This is the second sentence."

Response.Clear
Response.ContentType = "text/plain"
Response.AddHeader  "Content-Disposition", "attachment;filename=" & strFileName
Response.Write strContent
 
AWESOME!!! Exactly what I needed. Works like a charm. Cheers, Salute, Failte, and whatever else. You rock!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top