具体情况是这样:我做个文件下载的功能,别人发送请求过来,我根据对方的请求返回一个链接给他,他根据这个链接直接下载文件,现在对方要求下载的文件名中必须要有中文说明,但是我尝试用中文了,但是调试的时候发现下载时中文解析出来是乱码,对方说这个能解决,搜了下没找到具体的方案,这是我下载的源代码,是用C#写的,具体怎么实现中文地址的传递呢: public partial class download_cim : System.Web.UI.Page
{
public static string GetUrl(string file_name)
{
return JWebConfig.GetUrl(string.Format("/801_download/download_cim.aspx?file_name={0}", file_name));
} protected void Page_Load(object sender, EventArgs e)
{
if(Request.QueryString["file_name"] == null)
{
return;
} string file_name;
file_name = Request.QueryString["file_name"].ToString(); if (file_name == "" || file_name == null)
{
return;
} string remote_path = @"\data\graph\cim\"; JFileStoreManager client = new JRemoteFileStoreManager(); byte[] data = client.GetFileContent(string.Format("{0}{1}", remote_path, file_name)); Response.Clear(); Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(file_name)); Response.ContentType = "application/octet-stream";
Response.OutputStream.Write(data, 0, data.Length);
Response.End();
}
}当file_name 是中文时就是乱码,就无法解析,这个怎么弄呢?
{
public static string GetUrl(string file_name)
{
return JWebConfig.GetUrl(string.Format("/801_download/download_cim.aspx?file_name={0}", file_name));
} protected void Page_Load(object sender, EventArgs e)
{
if(Request.QueryString["file_name"] == null)
{
return;
} string file_name;
file_name = Request.QueryString["file_name"].ToString(); if (file_name == "" || file_name == null)
{
return;
} string remote_path = @"\data\graph\cim\"; JFileStoreManager client = new JRemoteFileStoreManager(); byte[] data = client.GetFileContent(string.Format("{0}{1}", remote_path, file_name)); Response.Clear(); Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(file_name)); Response.ContentType = "application/octet-stream";
Response.OutputStream.Write(data, 0, data.Length);
Response.End();
}
}当file_name 是中文时就是乱码,就无法解析,这个怎么弄呢?
解决方案 »
- 如何将DataRow中某一列转换成 sting数组???
- Win7下用VS2008开发的WinForm程序 在XP下运行报错
- 打开文件,为什么版本不一样就打不开,如何解决
- .net在发布网站时出现的错误
- 本地smtp发邮件的问题
- datagrid列宽怎么自动适应整个边框?内容详细说明
- 谁能解释一下并行存储、并行查询、并行数据管理中的并行是什么意思啊!
- 请问如何编程关闭显示器 和 调整屏幕亮度?
- 请教c#的继承性
- 思归,microsoft专家,设置安装程序中遇到奇怪的问题。。(无法注册模块,请与技术人员联系)
- DataGridView 按钮列,隐藏某些行的按钮
- 控制台程序怎么在main函数获取自己的进程名
System.Web.HttpUtility.UrlEncode((string)keywords, System.Text.Encoding.GetEncoding("UTF-8"))
System.Web.HttpUtility.UrlDecode((string)
后面一直用 str 就可以了