title: ASP.net download file Using HttpContext.Current.Response.TransmitFile in ASP.NET
body: <pre><code>public void Downloadfile(string sFileName, string sFilePath)
  {
      HttpContext.Current.Response.Clear();
      HttpContext.Current.Response.ClearContent();
      HttpContext.Current.Response.ClearHeaders();
      HttpContext.Current.Response.ContentType = "APPLICATION/OCTET-STREAM";
      String Header = "Attachment; Filename=" + sFileName;
      HttpContext.Current.Response.AppendHeader("Content-Disposition", Header);
      HttpContext.Current.Response.AppendHeader("Cache-Control", "no-cache");
      System.IO.FileInfo Dfile = new System.IO.FileInfo(HttpContext.Current.Server.MapPath(sFilePath));
      HttpContext.Current.Response.TransmitFile(Dfile.FullName);
      HttpContext.Current.ApplicationInstance.CompleteRequest();
  }
  </code></pre>
  
  <p>I have a download button, the click will return the call and download the corresponding file download, but sometimes file returns is detailt.aspx file. I do not understand what is happening.
  I need help. Thanks a lot</p>