当前位置: 代码迷 >> C# >> webform下载excel文件出错解决方案
  详细解决方案

webform下载excel文件出错解决方案

热度:8   发布时间:2016-05-05 03:22:23.0
webform下载excel文件出错

下载文件,下载下来是乱码的文件呢。不知道什么原因
下面是下载文件的代码
ExportHyper.NavigateUrl是文件的路径

FileInfo file = new FileInfo(ExportHyper.NavigateUrl);
            Response.Clear();
            Response.ClearHeaders();
            Response.Buffer = false;
            Response.ContentType = "application/octet-stream";
            Response.AppendHeader("Content-Disposition","attachment;filename="+HttpUtility.UrlEncode(file.Name,System.Text.Encoding.UTF8));
            Response.AppendHeader("Contet-Length", file.Length.ToString());
            Response.WriteFile(file.FullName);
            Response.Flush();

------解决思路----------------------
Response.ContentType = "application/octet-stream";
类型错误了

应该是
Response.ContentType = "application/ms-excel";
  相关解决方案