I’m creating a PDF file on the fly using ITextSharp and ASP.NET 1.1. My process is as follows –
- Create file on server
- Redirect browser to newly created PDF file so it is displayed to user
What I’d like to do is delete the PDF from the server as soon it is displayed in the users browser. The PDF file is large so it is not an option to hold it in memory, an initial write to the server is required. I’m currently using a solution that periodically polls for files then deletes them, but I’d prefer a solution that deletes the file immediately after it has been downloaded to the client machine. Is there a way to do this?
Instead of redirecting the browser to the created file you could serve the file yourself using you own HttpHandler. Then you could delete the file immediately after you served it or you could even create the file in memory.
Write the PDF file directly to the Client:
or read an already generated file ‘filename’, serve the file, delete it:
I didn’t try this code. This is just how I think it would work …