title: ASP C# Send File to Client
body: <p>Trying to send a file to the browser for download but after fiddling with it for over an hour can't seem to get it to work correctly.</p>
  
  <p>I'm using the following code</p>
  
  <pre><code>    string filePath = Server.MapPath("/exports/test.txt");
      string downloadedFileName = "test.txt";
  
      Response.ContentType = "text/plain";
      Response.AppendHeader("content-disposition", "attachment; filename=" + downloadedFileName);
      Response.TransmitFile(filePath);
      Response.End();
  </code></pre>
  
  <p>It downloads to the browser but the file is filled with HTML from the page instead of the contents of the file. If I write out the directory of server.MapPath the file is located in that directory. </p>
  
  <p>I'm eventually going to use this to send a accdb or mdb database to the browser, I'm just using txt as it's easy to find a proof of concept example online. What would I need to change outside of the ContentType if anything. Also would should the ContentType be for a database?</p>
  
  <p>Thanks for any help in advance!</p>