错误:无法显示 XML 页。
无法查看使用 样式表的 XML 输入。请更正错误然后单击 刷新 按钮,或稍后重试。
代码: System.Data.DataTable dt = BLL.product.GetProduct();
System.Data.DataSet ds = new DataSet();
ds.Tables.Add(dt.Copy());
ExcelIO ei = new ExcelIO();
bool s = ei.ExportExcel(ds, "upload/excel.xlsx");
if (s == true)
{
try
{
string filepath = Server.MapPath(".") + "\\" + "upload\\excel.xlsx";
if (File.Exists(filepath))
{
FileInfo file = new FileInfo(filepath);
if (file.IsReadOnly)
{
file.IsReadOnly = false;
}
Response.Clear();
Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
Response.AppendHeader("Content-Disposition ", "attachment;filename= " + Server.UrlEncode(file.Name));
Response.AppendHeader("Content-Length ", file.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(file.FullName); Response.Flush();
Response.End();
// HttpContext.Current.ApplicationInstance.CompleteRequest();
}
}
catch (Exception ex)
{
throw ex;
}
无法查看使用 样式表的 XML 输入。请更正错误然后单击 刷新 按钮,或稍后重试。
代码: System.Data.DataTable dt = BLL.product.GetProduct();
System.Data.DataSet ds = new DataSet();
ds.Tables.Add(dt.Copy());
ExcelIO ei = new ExcelIO();
bool s = ei.ExportExcel(ds, "upload/excel.xlsx");
if (s == true)
{
try
{
string filepath = Server.MapPath(".") + "\\" + "upload\\excel.xlsx";
if (File.Exists(filepath))
{
FileInfo file = new FileInfo(filepath);
if (file.IsReadOnly)
{
file.IsReadOnly = false;
}
Response.Clear();
Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
Response.AppendHeader("Content-Disposition ", "attachment;filename= " + Server.UrlEncode(file.Name));
Response.AppendHeader("Content-Length ", file.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(file.FullName); Response.Flush();
Response.End();
// HttpContext.Current.ApplicationInstance.CompleteRequest();
}
}
catch (Exception ex)
{
throw ex;
}
改成
Response.Write(ex.Message);
试试
当走到response.end()的时候,出现这个异常。搜了点资料,说吧response.end()改成 HttpContext.Current.ApplicationInstance.CompleteRequest();
,但是改了以后没事无法显示XML页
try
catch去掉就明白哪行错误了
错误:无法显示 XML 页。
无法查看使用 样式表的 XML 输入。请更正错误然后单击 刷新 按钮,或稍后重试。
Response.AppendHeader("Content-Length ", file.Length.ToString());这里面不要带空格 Response.AppendHeader("Content-Disposition", "attachment;filename= " + Server.UrlEncode(file.Name));
Response.AppendHeader("Content-Length", file.Length.ToString());