日期:2014-05-18  浏览次数:20388 次

文件下载问题
做一个文件管理的系统。我在一个datalist的ItemTemplate面板有我绑定到数据库的几个LABEL分别是显示文件名称,文件大小。。等等。我现在在里面添加一个LinkButton令它的CommandName="edit" 然后我在DataList1_EditCommand(这样主要是为了文件名)写了如下代码
C# code

        string strFileName = this.DataList1.DataKeys[e.Item.ItemIndex].ToString();//文件名
        string FullFileName = Page.Server.MapPath("Uploadfiles/") + strFileName;//文件的全路径名

        FileInfo DownloadFile = new FileInfo(FullFileName);
        Response.Clear();
        Response.Charset = "utf-8";
        Response.Buffer = true;
        this.EnableViewState = false;
        Response.ContentEncoding = System.Text.Encoding.UTF8;
        Response.AppendHeader("Content-Disposition ", "attachment;filename=" + strFileName);
        Response.ContentType = "application/unknown ";
        Response.WriteFile(FullFileName);
        Response.Flush();
        Response.Close();
        Response.End(); 


但是我一点击这个LinkButton会出先页面错误如下:


无法显示 XML 页。 
使用 样式表无法查看 XML 输入。请更正错误然后单击 刷新按钮,或以后重试。 


--------------------------------------------

文本内容中发现无效字符。处理资源 'http://localhost:47130/资源管理/Default.aspx' 时出错。第 1 行,位置: 3 

0&
本人是新手,请高手指教下,谢谢。。。
 


------解决方案--------------------
Response.AppendHeader("Content-Disposition ", "attachment;filename=" + strFileName);
Response.ContentType = "application/unknown ";

多了两个空格"Content-Disposition ", "application/unknown ";

Response.Buffer = true;//设置为False看看.