title: How to download pdf file using asp.net?
body: <p>I upload file and stored in Data folder in server</p>
  
  <p>File path:</p>
  
  <pre><code>Project Name
   |_bin
   |_css
   |_Data
     |_Mohamedfaisal.pdf
  </code></pre>
  
  <p>this is my asp.net code</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.IO;
  using System.Data;
  
  namespace Expatriates {
   public partial class FileUploadForm: System.Web.UI.Page {
    protected void Page_Load(object sender, EventArgs e) {
  
    }
  
    protected void Button1_Click(object sender, EventArgs e) {
     if (FileUpload1.HasFile) {
      FileUpload1.PostedFile.SaveAs(Server.MapPath("~/Data/") + FileUpload1.FileName);
     }
  
     DataTable dt = new DataTable();
     dt.Columns.Add("File", typeof(string));
     dt.Columns.Add("size", typeof(string));
     dt.Columns.Add("type", typeof(string));
  
     foreach(string strFile in Directory.GetFiles(Server.MapPath("~/Data/"))) {
      FileInfo fi = new FileInfo(strFile);
  
      dt.Rows.Add(fi.Name, fi.Length, fi.Extension);
     }
  
     GridView1.DataSource = dt;
     GridView1.DataBind();
    }
  
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) {
     if (e.CommandName == "Download") {
      Response.Clear();
      Response.Write(e.CommandArgument);
      Response.ContentType = "application/octect-stream";
      Response.AppendHeader("content-disposition", "filename=" + e.CommandArgument);
      Response.TransmitFile(Server.MapPath("~/Data/") + e.CommandArgument); // error occured
      Response.End();
     }
    }
   }
  }
  </code></pre>
  
  <p>Front End asp.net</p>
  
  <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true"     CodeBehind="FileUploadForm.aspx.cs" Inherits="Expatriates.FileUploadForm" %&gt;
  
  &lt;!DOCTYPE html&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head runat="server"&gt;
      &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
      &lt;div style="font-family:Arial;"&gt;
          &lt;asp:FileUpload ID="FileUpload1" runat="server" /&gt;
          &lt;asp:Button ID="Button1" runat="server" Text="Upload"     OnClick="Button1_Click" /&gt;
          &lt;br /&gt;
          &lt;br /&gt;
          &lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand"&gt;
              &lt;Columns&gt;
                  &lt;asp:TemplateField HeaderText="File"&gt;
                      &lt;ItemTemplate&gt;
                          &lt;asp:LinkButton ID="LinkButton1" runat="server" CommandName="Download" Text='&lt;%# Eval("File") %&gt;'&gt;&lt;/asp:LinkButton&gt;
                      &lt;/ItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
                  &lt;asp:BoundField DataField="Size" HeaderText="Size in Bytes" /&gt;
                  &lt;asp:BoundField DataField="Type" HeaderText="File Type" /&gt;
              &lt;/Columns&gt;
          &lt;/asp:GridView&gt;
      &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>my front end design
  <a href="http://i.stack.imgur.com/jiSop.png" rel="nofollow">UI design</a></p>
  
  <p>when I click that link it shows that following error message</p>
  
  <blockquote>
    <p>An exception of type 'System.IO.DirectoryNotFoundException' occurred
    in mscorlib.dll but was not handled in user code</p>
    
    <p>Additional information: Could not find a part of the path 'F:\Visual
    Studio Project\Expatriates\Expatriates\Data\'.</p>
  </blockquote>
  
  <p>Uploading file is working perfectly, But I am not getting a download. </p>