microkarl Posted March 12, 2008 Posted March 12, 2008 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 Quote Donald DUCK : YOU ARE FIRED!!!
Administrators PlausiblyDamp Posted March 12, 2008 Administrators Posted March 12, 2008 Rather than create and then delete a file on the server you could simple write the contents direct to the response objects outputstream http://www.xtremedotnettalk.com/showpost.php?p=447870&postcount=10 has a simple example. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
microkarl Posted March 12, 2008 Author Posted March 12, 2008 Thanks for the response, it actually works! The only concern that I have is would there be a threading problem? Quote Donald DUCK : YOU ARE FIRED!!!
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.