下载文件乱码问题的解决

在.Net中下载文件实际上就是往浏览器返回一个包含该文件的唯一url地址

由于url的编码为AscⅡ码,如果要下载文件名为中文的文件就可以会出现乱码,所以需要对文件名进行编码

            string fileName = "测试.docx";
            string encodeName = HttpUtility.UrlPathEncode(fileName);//对中文进行编码
            Response.ContentType = "application/octet-stream";
            Response.AppendHeader("Content-Disposition", "attachment;filename=" + encodeName);
            Response.WriteFile(Request.MapPath("~/Part1/Download/" + fileName));
            Response.End();

 

posted @ 2013-01-16 14:26  夜照亮了黑  阅读(822)  评论(0编辑  收藏  举报