title: How to download a file in asp.net using c#
body: <p>I have a web page used to display the information about files (like a name  and a pic ) of the file  based on the (query string) ((the files already will be saved on the server))</p>
  
  <p>the details of these files will display  within (data list)..
  how to creat a command button to download the file when click on it</p>
  
  <pre><code>void FillLessons()
  {
      SqlConnection cn = new SqlConnection(cs);
      cn.Open();
      SqlCommand cmd = new SqlCommand();
  
  
      string sqlStatment = "SELECT Lesson_Id,Lesson_Title,Subject_Id,Lesson_Img FROM [Ali].[dbo].[tblLessons] where Subject_Id ='" + Request.QueryString["id"].ToString() + "' ";
  
      cmd.CommandType = CommandType.Text;
      cmd.CommandText = sqlStatment;
      cmd.Connection = cn;
  
      DataTable dt = new DataTable();
  
      dt.Load(cmd.ExecuteReader());
  
      dllessons.DataSource = dt;
      dllessons.DataBind();
  }
  </code></pre>
  
  <p>I dont know how to extract the file name (Lesson_Title) from the data table (dt) to use it when I want to create a button to download the file??</p>
  
  <p>I have added a link button inside the data list and added command name=Download</p>
  
  <p>and CommandArgument='&lt;%# Eval("Lesson_Title") %>'</p>
  
  <p>than typed this code </p>
  
  <pre><code>   protected void dllessons_ItemCommand(object sender, DataListCommandEventArgs e)
      {
          if (e.CommandName == "Download")
          {
              Response.Clear();
              Response.ContentType = "application/octect-stream";
              Response.AppendHeader("content-disposistion", "filename=" + e.CommandArgument);
              Response.TransmitFile (Server.MapPath("~/My_Lessons/") + e.CommandArgument);
              Response.End();
          }
      }
  </code></pre>
  
  <p>but it still does not work??</p>
  
  <p>thanks </p>