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

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