在用这个方法把Response中的输出流输入到客户端的Excel文件时,执行到Response.Charset = "GB2312"; 时报:
异常信息:
异常类型: HttpException
异常消息: 服务器无法在发送 HTTP 标头之后设置内容类型。
执行到 Response.ContentType = "application/unknown";报:
服务器无法在发送 HTTP 标头之后设置内容类型.不知如何解答.望各朋友来看看..
/// <summary>
/// 把EXCEL表输入到客户端
/// </summary>
/// <param name="filePath"></param>
/// <param name="saveFileName"></param>
public void UploadFiles(String filePath, String saveFileName)
{
//定义选中的文件全名
try
{
//创建一个文件实体,方便对文件操作
System.IO.FileInfo finfo = new System.IO.FileInfo(filePath); //清空输出流出流.
Response.Clear();
Response.Charset = "GB2312";
Response.Buffer = true;
//关闭ViewState以提高速度;
this.EnableViewState = false;
//定义输出文件编码及类型和文件名
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(saveFileName, Encoding.UTF8).ToString());
//因为保存的文件类型不限,此处类型选择"unknown";
Response.ContentType = "application/unknown";
Response.WriteFile(filePath);
//清空并关闭输出流
Response.Flush();
Response.Close();
Response.End();
}
catch (IOException ex)
{
Response.Write(ex.Message);
} }
异常信息:
异常类型: HttpException
异常消息: 服务器无法在发送 HTTP 标头之后设置内容类型。
执行到 Response.ContentType = "application/unknown";报:
服务器无法在发送 HTTP 标头之后设置内容类型.不知如何解答.望各朋友来看看..
/// <summary>
/// 把EXCEL表输入到客户端
/// </summary>
/// <param name="filePath"></param>
/// <param name="saveFileName"></param>
public void UploadFiles(String filePath, String saveFileName)
{
//定义选中的文件全名
try
{
//创建一个文件实体,方便对文件操作
System.IO.FileInfo finfo = new System.IO.FileInfo(filePath); //清空输出流出流.
Response.Clear();
Response.Charset = "GB2312";
Response.Buffer = true;
//关闭ViewState以提高速度;
this.EnableViewState = false;
//定义输出文件编码及类型和文件名
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(saveFileName, Encoding.UTF8).ToString());
//因为保存的文件类型不限,此处类型选择"unknown";
Response.ContentType = "application/unknown";
Response.WriteFile(filePath);
//清空并关闭输出流
Response.Flush();
Response.Close();
Response.End();
}
catch (IOException ex)
{
Response.Write(ex.Message);
} }
/// 导出整张成品报表
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void LinkButton8_Click(object sender, EventArgs e)
{ Response.Write("<div id='mydiv' >");
Response.Write("_");
Response.Write("</div>");
Response.Write("<script>mydiv.innerText = '';</script>");
Response.Write("<script language=javascript>;");
Response.Write("var dots = 0;var dotmax = 10;function ShowWait()");
Response.Write("{var output; output = '正在装载页面,可能需要10分钟,请耐心等候';dots++;if(dots>=dotmax)dots=1;");
Response.Write("for(var x = 0;x < dots;x++){output += '·';}mydiv.innerText = output;}");
Response.Write("function StartShowWait(){mydiv.style.visibility = 'visible'; ");
Response.Write("window.setInterval('ShowWait()',1000);}");
Response.Write("function HideWait(){mydiv.style.visibility = 'hidden';mydiv.style.display='none';");
Response.Write("window.clearInterval();}");
Response.Write("StartShowWait();</script>");
Response.Flush();Thread.Sleep(10000);
.... Response.Write("<script language='javascript'> HideWait();</script>");
UploadFiles(sFile, DateTime.Now.Date.ToString() + "日成品报表");
}