How can I serve a dynamic file, and then clean it up?

J

Jason Barnett

I wrote an aspx page that creates a .pdf file upon request and transfers the
file to the client for viewing (via an Adobe Acrobat plug-in). Afterwards,
the file is no longer needed and should be deleted from the server. Here is
a code snippet as an example:

Response.ContentType = "application/pdf";
Response.Clear();
Response.TransmitFile(filename);
Response.Flush();
//Response.End();
System.IO.File.Delete(filename);

Could someone suggest a better way of getting the dynamic file to the client
while maintaining a clean server?
 
I

IanL

Instead of writing to the file to disk, you would use a memory stream.
Then transfer the binary data into a byte array, and use the Response
object to output it to the client.
Instead of using Response.TransmitFile use:

Response.BinaryWrite(TemporaryFileByteArray);

DotCodeDump: http://www.dotcodedump.com

+Ian Lintner
 
J

Jason Barnett

I'm actually using a 3rd party tool that generates the file. I have no
control over that. However, your suggestion helped me load the file into a
byte array, delete the file, and then write the binary data to the client.
Thanks!
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top