FineUI 官方论坛
标题:
输出文件流 出现乱码错误,有人能看看不?
[打印本页]
作者:
ziok2010
时间:
2014-1-15 16:14
标题:
输出文件流 出现乱码错误,有人能看看不?
我的代码:
string zipFileName = DateTime.Now.Ticks.ToString() + ".zip";
var FileNames = RowsAreSelected(Grid1, "FileNames", 0);
string[] FileArr = FileNames.Split(',');
List<string> files = new List<string>();
for (int i = 0; i < FileArr.Length; i++)
{
files.Add(FileArr[i].Substring(1, FileArr[i].Length - 2));
}
using (Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile(Encoding.UTF8))//解决中文乱码问题
{
foreach (var item in files)
{
zip.AddFile(Server.MapPath(string.Format("~/download/jcxxcj/{0}", item)), "");
}
zip.Save(Server.MapPath("~/download/jcxxcjzip/" + zipFileName));
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(zipFileName, System.Text.Encoding.UTF8));
FileStream fs = File.OpenRead(Server.MapPath("~/download/jcxxcjzip/" + zipFileName));
//定义缓冲区大小
byte[] buffer = new byte[10240000];
//第一次读取
int i = 0;
double filelength = fs.Length;
while (filelength > 0)
{
i = fs.Read(buffer, 0, buffer.Length);
Response.OutputStream.Write(buffer, 0, i);
filelength = filelength - i;
}
//关闭磁盘文件流
fs.Close();
//关闭输出流
Response.End();
}
}
错误截图:
作者:
sanshi
时间:
2014-1-15 18:50
参考示例:
http://fineui.com/demo/#/demo/grid/grid_excel.aspx
需要设置导出按钮的 EnableAjax="false" DisableControlBeforePostBack="false"
作者:
ziok2010
时间:
2014-1-16 09:59
谢谢三石 解决了~! 看来是ajax提交不能下载文件嘛~
作者:
水木山人
时间:
2014-1-17 16:17
能把大包下载的code分享下不?正好需要~谢谢~
欢迎光临 FineUI 官方论坛 (https://fineui.com/BBS/)
Powered by Discuz! X3.4