How to close current explorer window from C# code.

  • Thread starter Thread starter mamin
  • Start date Start date
M

mamin

Hi,
I need to send a file to a client and then close current window.

My code looks as follows:

Response.ContentType="application/bmp";
Response.AppendHeader("","attachment; filename=\"" + bmpFilePath +
"\"");
Response.WriteFile(bmpFilePath);
Response.Flush();
Response.End();

//now I need to close this window.

Anyone know how to do it?
 
Depending on the state of the window, you may not be able to. If you
CAN, your best best is to send a JavaScript close command. It's a
major security flaw to allow someone to close your application, so no
browser (not even IE) will allow for that. You need to get user
confirmation...

Start here...

Response.Write("<script>self.close();</script>");
 
In addition, I don't thing it would work doing it at the same time because
you would have to write javascript to the browser in addition to sending the
file. The browser is only seeing one stream of data so the javascript would
interfere with the binary stream and render the whole thing corrupt.
 
Back
Top