Help with Deleting a file after downloading

microkarl

Regular
Joined
Apr 22, 2004
Messages
88
Location
Morristown, NJ
Hi all,
I have implemented some code in my page that will generate a .txt file (on the fly) when the user click on an ASP button, then a download box will show up and so the user can download that file. But I want to delete the file right away after the file is finished downloading...

//Here's the code to generate the file... Everything ends @Response.End();

System.IO.FileInfo fileToDownload = new System.IO.FileInfo(myFileName);
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + myFileName);
Response.ContentType = "application/octet-stream";
Response.WriteFile(myFileName);
Response.End();

//I tried to change it to become the following, but still doesn't work...
//Response.Close();
//fileToDownload.Delete();

can anyone give me some hint?

Thanks,
Carl
 
Back
Top