附件下载,中文文件名乱码如何解决???
2008-01-15 15:48
696 查看
问:
我写了个程序,里面有文件要作为附件下载,英文文件名都正常,但中文文件名就会乱码,不知道如何解决,望高手指点。
代码如下:
=============================
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();
回答1:
System.IO.FileInfo file = new System.IO.FileInfo(path);
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();
回答2:
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment;filename="
+ HttpUtility.UrlEncode(DownloadFile.Name, System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
回答3:
GB2312也不行么?,实在不行你重新写一下试试
回答4:
这样写就OK了
Response.AddHeader("Content-Disposition","attachment;filename=" + HttpUtility.UrlEncode(测试.xls));
回答5:
编码问题
回答6:
再给你回复一次,我faint
string pathfile = @"F:/新建文件夹/1.txt"; //pathfile 是要下载的文件名称
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();
回答7:中文文件名的问题已解决,谢谢大家的帮忙。
我写了个程序,里面有文件要作为附件下载,英文文件名都正常,但中文文件名就会乱码,不知道如何解决,望高手指点。
代码如下:
=============================
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();
回答1:
System.IO.FileInfo file = new System.IO.FileInfo(path);
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();
回答2:
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment;filename="
+ HttpUtility.UrlEncode(DownloadFile.Name, System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
回答3:
GB2312也不行么?,实在不行你重新写一下试试
回答4:
这样写就OK了
Response.AddHeader("Content-Disposition","attachment;filename=" + HttpUtility.UrlEncode(测试.xls));
回答5:
编码问题
回答6:
再给你回复一次,我faint
string pathfile = @"F:/新建文件夹/1.txt"; //pathfile 是要下载的文件名称
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();
回答7:中文文件名的问题已解决,谢谢大家的帮忙。
相关文章推荐
- 解决Android4.3版本下,手机短彩接收中文文件名附件,中文名字的附件无法保存(第一步:解决从网络下载附件后,持久化时中文文件名中文乱码)
- 中文附件文件名过长,导致下载时文件名为乱码的错误解决办法
- 如何解决ASP.NET下载时的中文文件名乱码,与TXT文件中存在代码两个问题
- 解决PHP在IE浏览器下载文件,中文文件名乱码问题
- java下载中文文件名乱码的解决方法
- servlet下载,解决文件名中有中文下载路径出现乱码不能正常下载问题
- [转载]完美解决drupal6上传中文文件名附件乱码问题
- Struts2 .apk 文件下载及解决中文文件名乱码问题(转)
- 文件下载(解决中文文件名下载乱码问题) 收集
- javaweb网站下载文件中文文件名乱码解决方法
- 解决C# ASP .NET下载出现中文文件名乱码的问题
- IE下载时中文文件名乱码解决
- 跨浏览器PHP下载文件名中的中文乱码问题解决方法
- 【整理】解决php输出文件下载时文件名含中文时出现乱码
- c# web 下载文件(解决中文文件名乱码问题)
- Response.AddHeader实现下载_解决下载界面中文文件名乱码问题
- 【转】彻底解决Asp.net文件下载(Response.WriteFile)时文件名的中文乱码和空格异常问题
- 解决跨浏览器下PHP下载文件名中的中文乱码问题
- 文件下载 response.setHeader()下载中文文件名乱码问题 解决办法
- 用火狐浏览器下载中文文件名的文件乱码及其解决