Instead of redirecting the browser to the created file, you can use the file yourself using your own HttpHandler. You can then delete the file immediately after serving it, or even create a file in memory.
Write the PDF file directly to the client:
public class MyHandler : IHttpHandler { public void ProcessRequest(System.Web.HttpContext context) { context.Response.ContentType = "application/pdf";
or read the already generated file 'filename', open the file, delete it:
context.Response.Buffer = false; context.Response.BufferOutput = false; context.Response.ContentType = "application/pdf"; Stream outstream = context.Response.OutputStream; FileStream instream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read); byte[] buffer = new byte[BUFFER_SIZE]; int len; while ((len = instream.Read(buffer, 0, BUFFER_SIZE)) > 0) { outstream.Write(buffer, 0, len); } outstream.Flush(); instream.Close();
I have not tried this code. This is exactly how I think it will work ...
f3lix
source share