摘要:畫面控制項 下載成檔案
string fileName = "ABCDEF";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write("<meta http-equiv=Content-Type content=text/html;charset=UTF-8>");
fileName = HttpUtility.UrlEncode(fileName + ".doc", System.Text.Encoding.GetEncoding("UTF-8"));
HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", fileName));
HttpContext.Current.Response.ContentType = "application/ms-word";
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter htw = new HtmlTextWriter(sw))
{
try
{
tableExport.RenderControl(htw);
}
catch (Exception ex)
{
throw ex;
}
string rr = sw.Encoding.ToString();
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.End();
}
}