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

求大神指导啊 我的下载功能实现不了了

空空v5 发布于 2013-05-30 15:20, 657 次点击
这是我的代码 希望众大神帮忙看看 有问题不
protected void LinkButton1_Click1(object sender, EventArgs e)
    {
        LinkButton l = sender as LinkButton;
        DownLoad();
    }
    public void DownLoad()
    {
        string filepath = Server.MapPath("~") + "/" + l.ToolTip.Substring(2, l.ToolTip.Length - 2);
        if ((filepath))
        {
            FileInfo file = new FileInfo(filepath);
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
            Response.AddHeader("Content-Disposition", "attachment;filename=+=Server.UrlEncode(file.Name)");
            Response.AddHeader("Content-Disposition", file.Length.ToString());
            Response.ContentType = "application/octet-stream";
            Response.WriteFile(file.FullName);
            Response.End();
        }
    }
4 回复
#2
ysa_xiongfei2013-05-30 18:21
protected void Button1_Click(object sender, EventArgs e)
        {
            //定义输出的MIME类型
            Response.ContentType = "application/x-zip-compressed";
            //head中填加个meta 元素,filename下载文件的名称,显示在下载框中
            Response.AddHeader("Content-Disposition", "attachment;filename=lamdba.txt");
            //获取下载文件的路径
            string filename = Server.MapPath("./File/lambda.txt");
            //下载
            Response.TransmitFile(filename);

        }
#3
shangsharon2013-05-30 21:59
Response.AddHeader("Content-Disposition", "attachment;filename=+=Server.UrlEncode(file.Name)");
这句是不是错了???
Response.AddHeader("Content-Disposition", "attachment;filename="+Server.UrlEncode(file.Name));
#4
空空v52013-05-30 22:55
回复 3楼 shangsharon
谢谢啦  查出来了 是路径的问题
#5
邓士林2013-05-31 01:11
以下是引用shangsharon在2013-5-30 21:59:57的发言:

Response.AddHeader("Content-Disposition", "attachment;filename=+=Server.UrlEncode(file.Name)");
这句是不是错了???
Response.AddHeader("Content-Disposition", "attachment;filename="+Server.UrlEncode(file.Name));

路径
1