Click here to Skip to main content
16,016,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am getting an error "FileNotFoundException was not handled by user code"
[Could not find file 'C:\Users\cgrt\Desktop\MIS\docs\2010-2011']
this is my code :

protected void Button1_Click(object sender, EventArgs e)
    {
        string str = string.Format(@"select m.pcode, m.fyyear, m.date, m.FileName FROM upload AS m where m.pcode = '{0}'", DropDownList1.SelectedItem.Value.ToString());
        SqlDataAdapter da = new SqlDataAdapter(str, con);
        DataTable dt = new DataTable();
        da.Fill(dt);
        GridView1.DataSource = dt;
        GridView1.DataBind();
        DropDownList1.SelectedIndex = 0;

    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Dwn")
        {
            int index = Convert.ToInt32(e.CommandArgument);
            GridViewRow row = GridView1.Rows[index];
            string fName = row.Cells[1].Text;
            Response.ContentType = "application/octet-stream";
            Response.AddHeader("Content-Disposition", "attachment;filename=" + fName);
            Response.TransmitFile(Server.MapPath("~/docs/" + fName));
            Response.End();
        }

    }


my file is being shown in database table upload and its also stored in docs folder under mis but when i am pressing download button i am getting this error.
Posted

To download the file, you should also provide file extension in download path:

"C:\Users\cgrt\Desktop\MIS\docs\2010-2011"

here the extension of the file 2010-2011 must be appended.
 
Share this answer
 
There was just a simple error which was i wasnt includding the filename feild in my gridview thats it i added that and now i can download everything.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900