• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 687
  • Last Modified:

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

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.}
try
            {
                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);
                    Response.TransmitFile(filelocation);
                    Response.End();
                }
            }
            catch (Exception exp)
            {
                GlobalClass.JScript_Alert = @"<script language='javascript'>alert('" + exp.Message.ToString() + "');</script>";
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "confirmdwnldexpscript", GlobalClass.JScript_Alert, false);
                return;
            }

Open in new window

0
Tina_Bhole
Asked:
Tina_Bhole
1 Solution
 
dexterrajeshCommented:
hi,

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

refer: http://support.microsoft.com/kb/312629/EN-US/
0
 
Tina_BholeAuthor Commented:
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.

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now