Response.Rewrite不工作 [英] Response.Rewrite not working
本文介绍了Response.Rewrite不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
dt = (DataTable)ViewState["Data"];
if (dt.Rows.Count != 0)
{
string file = new ExcelHelper().ExportToExcel(dt);
string rootPath = HttpContext.Current.Server.MapPath("~\\ExcelFiles\\").ToString();
string localCopy = Guid.NewGuid().ToString() + ".xlsx";
File.Copy(file, rootPath + localCopy);
string str = rootPath + localCopy;
Response.Write(str); // not writing anything
Response.Redirect(str); // not going to path..
}
文件存在,路径也正确..
file is present , path is also correct..
推荐答案
Response.Write(str )只会打印页面顶部str中的字符串,我怀疑你真正想要的是什么。
然而,你然后调用Response.Redirect( str),如果str是正确的,将转到一个新页面,所以你以前的Response.Write无论如何都会丢失。
另外,你不能重定向因为你将它设置为本地文件路径。 str看起来像c:\inetpub \wwwroot \ MyApp\ExcelFiles。
如果你想将Excel文件下载到客户端你可以做Response.Redirect(〜/ ExcelFiles /+ fileName);
Response.Write(str) will just print the string that is in str at the top of the page which I doubt is what you really want.
However, you then call Response.Redirect(str) which, if str were correct, would go to a new page and so your previous Response.Write would be lost anyway.
Also, you can't redirect to str because you have it set to a local file path. str looks something like c:\inetpub\wwwroot\MyApp\ExcelFiles.
If you are trying to download the Excel file to the client you can do Response.Redirect("~/ExcelFiles/" + fileName);
这篇关于Response.Rewrite不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文