I have a file in server .
I want download this file .
I use this code
try
{
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.BufferOutput = true;
if (File.Exists(Server.MapPath("~/Upload/" + file)))
{
Response.AddHeader("Content-Disposition", "attachment; filename=" + file);
Response.ContentType = "application/octet-stream";
Response.WriteFile(("~/Upload/" + file));
Response.End();
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
else
{
if (Request.UrlReferrer != null)
{
Type csType = GetType();
string jsScript = "alert('File Not Found');";
ScriptManager.RegisterClientScriptBlock(Page, csType, "popup", jsScript, true);
}
}
}
catch (Exception ex)
{
string errorMsg = ex.Message;
ScriptManager.RegisterClientScriptBlock(Page, GetType(), "popup", errorMsg, true);
}
But when i use this, I get error
Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.
in code
Response.End();
How to download all types of files?