download a file from a web page: first time works, next times not

  • Thread starter Thread starter Fabio Mastria
  • Start date Start date
F

Fabio Mastria

Hi all

on a page aspx of my web application (vs2005, .net 2.0), I have an
imagebutton

Its click event looks like this:

filename = createFile(); //create a file on server filesystem

if (File.Exists(filename))
{
Response.Clear();
Response.ContentType = "application/x-download";
Response.AddHeader("Content-disposition", "attachment;filename=" +
Path.GetFileName(filename));
Response.WriteFile(filename);
Response.End();
}

First time user click on the image and download the file -> all done, all
ok...

If user retry to click on the image an exception is raised on the row
"Response.End()". The exception is not readable. The message (not the
Message field, but visual studio message) is "Impossible evaluate the
expression because the code is optimized or a native frame is at the start
of the calls stack"

Can Someone tell me how solve this problem?

Thank you all
Fabio
 
Back
Top