generate custom file for download

  • Thread starter Thread starter Paul
  • Start date Start date
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?
 
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
 
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
 
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
 
Back
Top