在Response.Writefile之后,ASP.NET页面呈现为空白 [英] ASP.NET Page rendered blank after Response.Writefile
本文介绍了在Response.Writefile之后,ASP.NET页面呈现为空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编写了这个代码,用于在click事件中将数据导出为excel。导出工作正常,只是在此按钮单击时页面呈现为空白。
有人能告诉我这段代码中缺少什么.. ??
受保护 void btnExportPDF_Click( object sender,EventArgs e)
{
if (!string.IsNullOrEmpty(hndPdfpath.Value))
{
// 这是一个重要的标题部分,通知客户端下载此文件。
Response.AppendHeader( content -disposition, attachment; filename = + Path.GetFileName(hndPdfpath.Value ));
FileInfo flnInfo = new FileInfo(hndPdfpath.Value.Trim());
if (flnInfo.Extension.ToLower()== .xlsx || flnInfo.Extension.ToLower()== 。xls )
{
Response.ContentType = application / Excel;
}
else
{
Response.ContentType = Application / pdf;
}
// 将文件直接写入HTTP内容输出流。
Response.WriteFile(hndPdfpath.Value);
}
}
解决方案
您好,
如需下载文件,请使用< pre lang =c#> public void DownloadFile( string filePath)
{
..
}来自以下链接
带进度条的ASP.NET文件上传 [ ^ ]
谢谢,
I have this code written to export data to excel in a click event. The export works fine except that the page is rendered blank on this button click.
Can somebody tell me what I am missing in this code..??
protected void btnExportPDF_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(hndPdfpath.Value))
{
// This is an important header part that informs the client to download this file.
Response.AppendHeader("content-disposition", "attachment; filename=" + Path.GetFileName(hndPdfpath.Value));
FileInfo flnInfo = new FileInfo(hndPdfpath.Value.Trim());
if (flnInfo.Extension.ToLower() == ".xlsx" || flnInfo.Extension.ToLower() == ".xls")
{
Response.ContentType = "application/Excel";
}
else
{
Response.ContentType = "Application/pdf";
}
//Write the file directly to the HTTP content output stream.
Response.WriteFile(hndPdfpath.Value);
}
}
解决方案
Hello,
For downloading file please usepublic void DownloadFile(string filePath) { .. }from following link
ASP.NET File Upload with Progress Bar[^]
Thanks,
这篇关于在Response.Writefile之后,ASP.NET页面呈现为空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文