Download all types of files from server using ASP.NET
<p>I have a file in server .</p>

<p>I want download this file .</p>

<p>I use this code </p>

<pre><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);
    }
</code></pre>

<p>But when i use this, I get error </p>

<blockquote>
  <p>Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.</p>
</blockquote>

<p>in code </p>

<blockquote>
  <p>Response.End();</p>
</blockquote>

<p>How to download all types of files?</p>
