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))
the details of these files will display within (data list).. how to creat a command button to download the file when click on it
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(); } 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??
I have added a link button inside the data list and added command name=Download
and CommandArgument='<%# Eval("Lesson_Title") %>'
than typed this 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(); } } but it still does not work??
thanks