May be it is a Duplicate question. But my case is something different. I have a page to download the text file. In the page first i decrypt the text file into string plainText
. then write that string into a file and upload to a folder named as Decrypted Files. The download that decrypted file and delete previously saved file.
here is my code for download
//Write the decrypted text to folder in the server.
System.IO.File.WriteAllText(Server.MapPath("~/Decrypted Files/" + FileName), plainText);
//Code for Download
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename='" + FileName + "'");
Response.WriteFile(Server.MapPath("~/Decrypted Files/" + FileName));
//Delete File from the folder
if (System.IO.File.Exists(Server.MapPath("~/Decrypted Files/" + FileName)))
{
System.IO.File.Delete((Server.MapPath("~/Decrypted Files/" + FileName)));
}
Response.End();
But The code execution not continue from Response.End();
and the .aspx page not finishing its loading. What is wrong with my code ?