Я хочу ввести данные из GridView в документ Word и загрузить их с клиента
var gd = new GridView
{
DataSource = li,
AutoGenerateColumns = true,
};
gd.DataBind();
if (gd.Rows.Count > 0)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + "List" + DateTime.Now.ToString("dd.MM.yyyy") + ".doc");
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.ContentType = "application/ms-word";
HttpContext.Current.Response.Charset = "UTF-8";
HttpContext.Current.Response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble());
var oStringWriter = new System.IO.StringWriter();
var oHtmlTextWriter = new HtmlTextWriter(oStringWriter);
gd.RenderControl(oHtmlTextWriter);
HttpContext.Current.Response.Output.Write(oStringWriter.ToString());
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
ОШИБКА (строки обернуты):
Sys.WebForms.PageRequestManagerParserErrorException:
Sys.WebForms.PageRequestManagerParserErrorException:
The message received from the server could not be parsed.' when calling method:
[nsIDOMEventListener::handleEvent]
[Break On This Error]
Filtered chrome url chrome://firebug/content/net/spy.js
spy.js (line 807)
<System>
1 ответ
Решение
Попробуй это:
Response.ContentType = "application/octet-stream"