下载文件名为中文的文件问题
通常用attachment; filename=" + HttpUtility.UrlEncode("EE.JPG",System.Text.Encoding.UTF8)
解决不能下载中文名的文件,但是我现在把文件直接存放在数据库中而不是存放在磁盘上,应该如何解决这个问题呢?
现在用这个只能正常下载英文名文件
if(dr.Read())
{
Response.Clear();
Response.ContentType="application/octet-stream";
Response.AddHeader("Content-Type",dr["type"].ToString()) Response.BinaryWrite((byte[])dr["contents"]);
}
第一次做这个~请各位指教~~
问题点数:50、回复次数:12Top
1 楼hzw66(超越理想)回复于 2005-09-04 11:04:21 得分 5
用这个编码试试:
System.Text.Encoding.DefaultTop
2 楼byyt(KingCobra)回复于 2005-09-04 11:12:56 得分 0
这个应该放哪里呢?
对Response.AddHeader的参数还不是太了解~望指教Top
3 楼byyt(KingCobra)回复于 2005-09-04 11:17:12 得分 0
最好能给出一个 从数据库读取中文名文件的例子~我在网上找了好多 都没从数据库读中文文件的例子Top
4 楼hackate(兰花开香入梦境,独思佳人亦飘然!!)回复于 2005-09-04 11:33:04 得分 5
see:
http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=5206Top
5 楼byyt(KingCobra)回复于 2005-09-04 11:36:05 得分 0
搞定了~~
还是谢谢哈
楼上的地址 我也去看看先~~Top
6 楼byyt(KingCobra)回复于 2005-09-04 11:39:27 得分 0
hackate(兰花开香入梦境,独思佳人亦飘然!!)
你说的好象还是从磁盘上读取吧~
我现在用的方法是 在上传的页面 指定
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
就可以正常下载了
不知道还有没别的方法,各位讨论下,我也好学习学习Top
7 楼hackate(兰花开香入梦境,独思佳人亦飘然!!)回复于 2005-09-04 11:52:13 得分 5
你这样啊.那你设置web.config里的
<globalization
requestEncoding="GB2312"
responseEncoding="GB2312"
/>
都为gb2312看看是否可行?Top
8 楼lovefootball(蟑螂(生活就是扯淡--做人要放低姿态))回复于 2005-09-04 13:42:13 得分 5
改成GB2312好像有时候还是有问题
还是给加个编码方式保险些Top
9 楼triffang(冲凉不除3)回复于 2005-09-04 15:00:58 得分 0
MarkTop
10 楼GDNPC(烟锁池塘柳,炮镇海城楼)回复于 2005-09-04 15:06:03 得分 15
string path=Server.MapPath(Request["File"]);
System.IO.FileInfo file=new System.IO.FileInfo(path);
Response.Clear();
Response.ClearHeaders();
Response.Buffer=false;
//Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.AddHeader("Content-DisPosition","attachment;filename="+HttpUtility.UrlEncode(file.Name).ToString());
Response.AddHeader("Content-Length",file.Length.ToString());
Response.ContentType="application/octet-stream";
Response.WriteFile(file.FullName);
Response.Flush();
Response.End();Top
11 楼wingspread(翼展)回复于 2005-09-04 16:34:44 得分 15
说明:从保存到数据库中的附件,以文件下载的方式下载
可能在细节上处理的不是很好,但是肯定能够使用
// 在此处放置用户代码以初始化页面
string id=Request["id"].ToString();
if (id.Length>0)
{
string sql="select id,fjm as fjmc,fujian as fjcontent from xxfb_fujian where id="+id;
int count=dbman.GetRowCount(sql);
dbman.Close();
if(count>0)
{
dbman.GetRowRecord(sql);
this.Response.Buffer=true;
this.Response.Clear();
this.Response.ContentType = Convert.ToString(dbman.ds.Tables[0].Rows[0]["fjtype"].ToString());
this.Response.AddHeader("Content-Disposition:", "attachment; filename=" + HttpUtility.UrlEncode(dbman.ds.Tables[0].Rows[0]["fjmc"].ToString()));
object dbValue = dbman.ds.Tables[0].Rows[0]["fjcontent"];
byte[] file = (byte[])dbValue;
this.Response.BinaryWrite(file);
this.Response.Flush();
this.Response.Clear();
this.Response.End();
}
dbman.Close();
}
Top
12 楼luckyprg(lucky)回复于 2005-10-26 19:47:11 得分 0
最重要的是HttpUtility.UrlEncode(file.Name).ToString()这里。
Mark.Top




