FineUI 官方论坛
标题:
下载出现乱码
[打印本页]
作者:
宇洋
时间:
2014-8-12 11:41
标题:
下载出现乱码
我是在后台用NPOI自动生成的excel文档,在表格行中进行下载。但是每次点击下载后多出现以下的乱码窗口。这是怎么回事?以前重来没有遇到过,请大家帮我看看。
[attach]6194[/attach]
以下是代码:
<f:Grid runat="server" ID="gridReport" ShowBorder="true" ShowHeader="false" AutoScroll="true"
AllowPaging="true" PageSize="12" Title="银行报表列表" DataKeyNames="ReportID" ForceFit="true"
EnableCheckBoxSelect="true" EnableTextSelection="true" ClearSelectedRowsAfterPaging="false"
EnableAlternateRowColor="true" EnableMouseOverColor="true" IsDatabasePaging="true"
>
<Columns>
<f:BoundField Width="30px" DataField="ReportID" HeaderText="ID" Hidden="true" />
<f:BoundField Width="200px" DataField="ReportTitle" HeaderText="报表名称" />
<f:BoundField Width="180px" DataField="ReportArea" HeaderText="报表所属地区" />
<f:BoundField Width="150px" DataField="ReportTimeRange" HeaderText="报表时间" />
<f:BoundField Width="80px" DataField="ReportCreator" HeaderText="报表创建人" />
<f:BoundField Width="80px" DataField="ReportCreateTime" HeaderText="报表创建时间" />
<f:BoundField Width="70px" DataField="ReportPersonCount" HeaderText="总人数" />
<f:BoundField Width="80px" DataField="ReportTotalAmount" HeaderText="总金额" />
<f
inkButtonField HeaderText="报表下载" Text="报表下载" Width="60px" EnableAjax="false" CommandName="Download" />
</Columns>
</f:Grid>
cs
void gridReport_RowCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == "Download")
{
string id = gridReport.Rows[e.RowIndex].Values[0].ToString();
string strFile = Subsidy_ReportBLL.GetSingleModelByID(id).ReportPath;
FileInfo fi = new FileInfo(strFile);
Response.ClearContent();
Response.Buffer = true;
Response.Charset = "GB2312";
Response.AddHeader("content-disposition", "attachment; filename=" + strFile);
Response.AddHeader("content-length", fi.Length.ToString());
Response.ContentType = "application/ms-excel";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.WriteFile(fi.FullName);
Response.Flush();
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
}
作者:
sanshi
时间:
2014-8-12 13:06
请用空项目重现。
按道理说你的下载按钮已经设置了EnableAjax=false,不会出现这样的对话框
作者:
beingtop
时间:
2014-8-13 09:50
把:
Response.Flush();
HttpContext.Current.ApplicationInstance.CompleteRequest();
改为
Response.End();
试试
作者:
beingtop
时间:
2014-8-13 09:54
还有
Response.Charset = "GB2312";
和
Response.ContentEncoding = System.Text.Encoding.UTF8;
字符编码最好一至
作者:
xxdddail
时间:
2014-8-22 18:05
我在下载按钮没设置EnableAjax=false时,出现了相似的问题。设置后,就OK了。
欢迎光临 FineUI 官方论坛 (https://fineui.com/BBS/)
Powered by Discuz! X3.4