如何保存一个Word文档到我的文件系统,而不是打印出来的? [英] How do I save a word document to my file system instead of printing it out?

查看:138
本文介绍了如何保存一个Word文档到我的文件系统,而不是打印出来的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序打印我的div来这样一个word文档:

In my application I print my div to a word document like this:

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的时候,我就会宣布的路径和现有的模板文件。

Instead of opening it on the browser How would I go about saving it to a path? Generally when using ItextSharp I would declare the path and the existing template file.

private static string AppRelativePath_1page = "~/DesktopModules/MyFolder";
private static string AppAbsolutePath_1page = HttpContext.Current.Server.MapPath(AppRelativePath_1page);

在这种情况下,没有现成的模板文件。我怎么会去我的服务器文件夹创建此文件?

In this case there is no existing template file. How would I go about creating this file in my server folder?

推荐答案

打开StreamWriter的,而不是写在响应对象,写信给你的StreamWriter。

Open a StreamWriter, and instead of writing to the Response object, write to your StreamWriter.

这篇关于如何保存一个Word文档到我的文件系统,而不是打印出来的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆