注册 登录
编程论坛 ASP.NET技术论坛

怎么实现 下载?

lovegosh 发布于 2008-04-23 23:52, 776 次点击
我已经上传了文件到服务器,并把路径什么的存到了数据库.
请问怎么实现下载?
7 回复
#2
闫温学2008-04-24 08:05
很简单,建立一个链接指向要下载的文件就可以了
#3
jalonlovesja2008-04-24 09:14
protected void btnFileDown_Click(object sender, EventArgs e)
    {
        SKK.BBL.NewClothList client = new SKK.BBL.NewClothList();
        Button btn = sender as Button;
        int CC_id = Convert.ToInt32();
        DataSet ds = client.NewClothSelectByID(CC_id) as DataSet;
        string FileName = ds.Tables[0].Rows[0]["Annex"].ToString();
        if (string.IsNullOrEmpty(FileName))
        {
            (this, "此文件没在系统里,请与有关人员联系");
        }
        else
        {
             file = new (FileName);
            string ct = Response.ContentType;
            Response.Clear();
            Response.AppendHeader("Content-Disposition", "attachment; filename=" + file.Name);
            Response.AppendHeader("Content-Length", file.Length.ToString());
            Response.ContentType = "application/octet-stream";
            Response.WriteFile(file.FullName);
            Response.End();
            file = null;
            Response.Clear();
            Response.ContentType = ct;
        }
    }
上面是下载的代码,你自己去看看吧!!!
#4
lovegosh2008-04-24 09:52
SKK.BBL.NewClothList client = new SKK.BBL.NewClothList();
是什么啊

不明白

要加什么头文件?
#5
lovegosh2008-04-24 09:56
难道不用从数据库读出什么吗?

代码不是很明白.
我主要是不明白,点击下载按钮时怎么弹出那个保存的框之类的
#6
jalonlovesja2008-04-24 12:53
file = new (FileName);
            string ct = Response.ContentType;
            Response.Clear();
            Response.AppendHeader("Content-Disposition", "attachment; filename=" + file.Name);
            Response.AppendHeader("Content-Length", file.Length.ToString());
            Response.ContentType = "application/octet-stream";
            Response.WriteFile(file.FullName);
            Response.End();
            file = null;
            Response.Clear();
            Response.ContentType = ct;
你看这些代码了,其他跟下载没关系的.那是我从数据库中读取出来的代码
#7
lovegosh2008-04-24 19:37
Response.WriteFile(file.FullName);

FullMame????   FileName 吧
#8
hebingbing2008-04-24 19:43
小弟,身高1.60米,农村户口,小学文化,家有农田1亩.
欣赏你的直率……
1