从gridview列下载存储在数据库中的文件的问题? [英] problems in downloading the file stored in database from gridview column?

查看:69
本文介绍了从gridview列下载存储在数据库中的文件的问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到错误用户代码未处理FileNotFoundException

[无法找到文件''C:\ Users \cgrt \Desktop \MIS \ docs \\ _2010-2011'']

这是我的代码:



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();
        }

    }





我的文件显示在数据库表上传中并且还存储了在docs文件夹下错误但当我按下载按钮时我收到此错误。



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.

推荐答案

要下载文件,您还应该在下载路径中提供文件扩展名:



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



这里必须附加文件2010-2011的扩展名。
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.


只有一个简单的错误,我在gridview中包含了文件名字段,这就是我补充说,现在我可以下载所有内容。
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.


这篇关于从gridview列下载存储在数据库中的文件的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆