如何将 word 文档保存到我的文件系统而不是打印出来?
How do I save a word document to my file system instead of printing it out?
在我的应用程序中,我将 div 打印到这样的 word 文档中:
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=testme.doc");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/doc";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
divExport.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
而不是在浏览器上打开它 我该如何将它保存到路径中?通常在使用 ItextSharp 时,我会声明路径和现有模板文件。
private static string AppRelativePath_1page = "~/DesktopModules/MyFolder";
private static string AppAbsolutePath_1page = HttpContext.Current.Server.MapPath(AppRelativePath_1page);
在这种情况下,没有现成的模板文件。我将如何在我的服务器文件夹中创建此文件?
打开一个 StreamWriter,而不是写入 Response
对象,写入您的 StreamWriter。
您可以使用 Streamwriter 来完成
using (StreamWriter sw = new StreamWriter(Path))
{
sw.Write(stringWrite.ToString());
}
在我的应用程序中,我将 div 打印到这样的 word 文档中:
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=testme.doc");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/doc";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
divExport.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
而不是在浏览器上打开它 我该如何将它保存到路径中?通常在使用 ItextSharp 时,我会声明路径和现有模板文件。
private static string AppRelativePath_1page = "~/DesktopModules/MyFolder";
private static string AppAbsolutePath_1page = HttpContext.Current.Server.MapPath(AppRelativePath_1page);
在这种情况下,没有现成的模板文件。我将如何在我的服务器文件夹中创建此文件?
打开一个 StreamWriter,而不是写入 Response
对象,写入您的 StreamWriter。
您可以使用 Streamwriter 来完成
using (StreamWriter sw = new StreamWriter(Path))
{
sw.Write(stringWrite.ToString());
}