我写了个程序,里面有文件要作为附件下载,英文文件名都正常,但中文文件名就会乱码,不知道如何解决,望高手指点。代码如下:
=============================
Response.Clear();
Response.BufferOutput=true;
Response.Charset="utf-8";//此处用“GB2312”也不行
Response.AppendHeader("Content-Disposition","attachment;filename=测试.xls");
Response.ContentType = "application/vnd.ms-excel";
FileInfo mf=new FileInfo(sFile);
FileStream fs=mf.OpenRead();
Response.WriteFile(fs.Handle,0,mf.Length);
fs.Close();
=============================
Response.Clear();
Response.BufferOutput=true;
Response.Charset="utf-8";//此处用“GB2312”也不行
Response.AppendHeader("Content-Disposition","attachment;filename=测试.xls");
Response.ContentType = "application/vnd.ms-excel";
FileInfo mf=new FileInfo(sFile);
FileStream fs=mf.OpenRead();
Response.WriteFile(fs.Handle,0,mf.Length);
fs.Close();
解决方案 »
- 急,,,求救,,怎么动态操作
- iis 问题
- 求助:关于使用Paypal Payflow网关
- 大家来看,问个session和对象转换的简单问题,顶者有分。。。
- 请问如何在aspx的脚本程序的定时器处理程序中更新DataGrid这样的与数据库绑定的Web窗体控件?
- 使用EditCommandColumn,并使用boundcolumn动态榜定数据,为什么处罚edit事件的时候,事件e中只有头一列,
- 单击Repeater中的Button,ItemCommand事件为什么会执行2次啊???
- 我的正则怎么不取取到文章内啊
- 关于自定义控件的问题--让我头痛啊// 100'
- 请教:事务中插入一条记录,尚未提交,可以查询到这条记录吗?
- ActiveX 参数问题
- 一期改版完成!请大家鉴赏。。。(没分了就不散了^_^)
Response.Clear();
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
// 添加头信息,为"文件下载/另存为"对话框指定默认文件名
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(name));
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/octet-stream";
// 把文件流发送到客户端
Response.WriteFile(file.FullName);
// 停止页面的执行
Response.End();
Response.AppendHeader("Content-Disposition", "attachment;filename="
+ HttpUtility.UrlEncode(DownloadFile.Name, System.Text.Encoding.UTF8)); Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
Response.AddHeader("Content-Disposition","attachment;filename=" + HttpUtility.UrlEncode(测试.xls));
System.IO.FileInfo file = new System.IO.FileInfo(pathfile);
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(file.Name));
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(file.FullName);
Response.End();