How to close current explorer window from C# code.

Discussion in 'ASP .Net' started by mamin@o2.pl, Oct 9, 2006.

  1. Guest

    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?
    , Oct 9, 2006
    #1
    1. Advertising

  2. q Guest

    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>");

    On Oct 9, 9:48 am, wrote:
    > 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?
    q, Oct 9, 2006
    #2
    1. Advertising

  3. 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.


    --
    Hope this helps,
    Mark Fitzpatrick
    Former Microsoft FrontPage MVP 199?-2006

    <> wrote in message
    news:...
    > 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?
    >
    Mark Fitzpatrick, Oct 9, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    6
    Views:
    8,807
    sateeshranga
    Aug 7, 2008
  2. Iñaki Baz Castillo
    Replies:
    7
    Views:
    826
    Iñaki Baz Castillo
    Jan 12, 2010
  3. Geoff Wilkins

    window.opener.close() and Internet Explorer 6

    Geoff Wilkins, Apr 3, 2004, in forum: Javascript
    Replies:
    0
    Views:
    120
    Geoff Wilkins
    Apr 3, 2004
  4. Shang Wenbin

    close current window using window.close()

    Shang Wenbin, Sep 1, 2005, in forum: Javascript
    Replies:
    10
    Views:
    357
    Gérard Talbot
    Sep 2, 2005
  5. Jan Tovgaard

    Window.close and Explorer 7 problem!

    Jan Tovgaard, Nov 20, 2006, in forum: Javascript
    Replies:
    36
    Views:
    278
    The Magpie
    Nov 29, 2006
Loading...

Share This Page