An HttpHandler is in charge of dispatching file downloads to the end user using HttpResponse.TransmitFile
. This file needs to be deleted after the download is completed, however if the file is deleted before HttpResponse.End
then the file is missing and the download fails, and any code after HttpResponse.End
is not executed.
What would be the best way to delete this file after the download is completed and the HttpResponse
is ended?
public void ProcessRequest(HttpContext context)
{
HttpResponse r = context.Response;
string filePath = context.Request.QueryString["filePath"];
string fName = context.Request.QueryString["fname"];
r.AddHeader("content-disposition", "inline; filename=\"" + fName + "\"");
r.TransmitFile(fullPath);
r.End();
}