Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Donald DUCK : YOU ARE FIRED!!!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...