generate custom file for download

P

Paul

I need a way of creating a custom file which can be downloaded by a user.
The file needs to be customized pre user (ie serial number built in).
Creating the file is no problem. The problem is how can several files be
created at the same time (ie several users logged in to the web site at once
wanting to download their file). A temporaty file can easily be created,
but how does the file get deleted after the user downloads it (or aborts the
download), and how can the file name be the same for all users?
 
D

Darrin J Olson

Do you need to keep a copy of the file? If it is generated "on the fly" and
they download it at the time they request it, can you just keep the file as
a fileStream?

I do something similar. When they request the file, I'll pop-up another
..aspx page with a parameter or session var that has the information on what
to create in the file. The new .aspx page will clear the output, and stream
out the file. This will prompt the user to download the file without
actually showing another window to open and not losing the page they are on.

Would something like that work?

-Darrin
 
P

Paul

Yes, it is created "On the fly", I don't need to keep a copy.

Sounds like your solution would work. Do you have sample code?

thanks for your reply
 
D

Darrin J Olson

Here is an example of clearing the output and sending your stream. In this
example I'm sending PDF files created on the fly.

Stream _strm = null;

//Insert code here to set _strm to some inherited stream object.

Response.ClearHeaders();
Response.ClearContent();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "inline;
filename=Estimate.pdf");

byte[] _buffer = new byte[_strm.Length];
_strm.Read(_buffer, 0, int.Parse(_strm.Length.ToString()));
Response.BinaryWrite(_buffer);
Response.Flush();


Hope this helps!
-Darrin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top