上传下载附件的服务 中文乱码问题 在线求解
具体如下:
上传用的RedControl的redUpload .
下载服务:
string fileName = HttpUtility.UrlDecode(context.Request.QueryString["FileName"], Encoding.GetEncoding("UTF-8")); //context.Response.ContentEncoding = System.Text.Encoding.Unicode; string relativefilePath = context.Request.QueryString["FilePath"]; //文件相对路径 string filePath = context.Server.MapPath(relativefilePath); string strType = context.Request.QueryString["ViewType"]; FileInfo fileInfo = new FileInfo(filePath); if (fileInfo.Exists) { context.Response.Clear(); context.Response.ClearHeaders(); context.Response.Buffer = true; context.Response.Charset = "GB2312"; context.Response.ContentType = "application/octet-stream"; context.Response.ContentEncoding = System.Text.Encoding.UTF8; //弹出下载框 if (strType != "View") { context.Response.AppendHeader("Content-disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)); } else { //直接打开 context.Response.AppendHeader("Content-disposition", "inline;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)); } context.Response.AddHeader("Content-Length", fileInfo.Length.ToString()); context.Response.WriteFile(filePath); context.Response.Flush(); context.Response.End(); } }
<globalization requestEncoding="gb2312" responseEncoding="utf-8" fileEncoding="utf-8"/>