Response.Write()を使用して、エクスポートされたWord文書ファイルを保存することは可能ですか。正常に変換されると、[保存/開く]ダイアログボックスが表示されます。しかし、私はこのファイルをフォルダに保存する必要があります。この問題を解決するために私を助けてください。
Docコードへの変換を以下に追加します。
private void ExportDataSetToWordDoc()
{
try
{
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", DateTime.Today.ToShortDateString().Replace("/", "").Replace("-", "") + "_" + DateTime.Now.ToShortDateString() + ".doc"));
Response.ContentType = "application/ms-word";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
tblMain.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
catch (ThreadAbortException ex)
{
Common.LogError(ex);
}
}