Display Save As dialog box to User when attempting to download file from windows web server in

Posted on 2011-10-27
Last Modified: 2012-08-14
Could someone please explain how can I display Save As dialog box to user when attempting to download file (any format and any size - from few kilobytes to 20 MB) from Windows Server to local machine. I am getting following error. Please see the code.

[System.Threading.ThreadAbortException] = {Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.}
                string selectedFile = Request.Form["grdRdo"];
                string filelocation = Server.MapPath("Downloads\\Hotfixes") + "\\" + selectedFile;
                if (File.Exists(filelocation))
                    Response.ContentType = "All Files";
                    Response.AppendHeader("Content-Disposition", "attachment; filename="+ selectedFile);
            catch (Exception exp)
                GlobalClass.JScript_Alert = @"<script language='javascript'>alert('" + exp.Message.ToString() + "');</script>";
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "confirmdwnldexpscript", GlobalClass.JScript_Alert, false);

Open in new window

Question by:Tina_Bhole
    LVL 9

    Accepted Solution


    For Response.End, call the HttpContext.Current.ApplicationInstance.CompleteRequest method instead of Response.End to bypass the code execution to the Application_EndRequest event.


    Author Comment

    Hi dexterrajesh,

    Thanks for your response.

    I replaced Response.End() with HttpContext.Current.ApplicationInstance.CompleteRequest();
    still I didn't get the Save As dialog box for the file.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now