在线等==急求C#对 word操作报错,有能力的帮忙解决下。谢谢。

生活 2010-01-05 09:18:28
以下这段代码 在vs运行条件下 可以通过,但是发布到本地机IIS上就会报错,
消息筛选器显示应用程序正在使用中。 (异常来自 HRESULT:0x8001010A (RPC_E_SERVERCALL_RETRYLATER))
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.Runtime.InteropServices.COMException: 消息筛选器显示应用程序正在使用中。 (异常来自 HRESULT:0x8001010A (RPC_E_SERVERCALL_RETRYLATER))

行 56: ref missing, ref missing, ref missing);
行 57:
行 58: aDoc.PageSetup.PageHeight = 1050.0F;
行 59: aDoc.PageSetup.PageWidth = 710.0F;
行 60: aDoc.PageSetup.TopMargin = 5;

堆栈跟踪:


[COMException (0x8001010a): 消息筛选器显示应用程序正在使用中。 (异常来自 HRESULT:0x8001010A (RPC_E_SERVERCALL_RETRYLATER))]
Microsoft.Office.Interop.Word.DocumentClass.get_PageSetup() +0
MyFaxWin.MSearch.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\liten000\桌面\新建文件夹\MyFaxWin\MSearch.aspx.cs:58
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061


string path = "D:\11.doc"
protected void Page_Load(object sender, EventArgs e)
{

ExpertControl(this, path);

object fileName = path;
object read_only = false;
object visible = true;
object isFalse = false;

// the way to handle parameters you don't care about in .NET
object missing = System.Reflection.Missing.Value;

//Open the document that was chosen by the dialog
ApplicationClass wordApp = new ApplicationClass();
wordApp.Visible = false;

Document aDoc = wordApp.Documents.Open(
ref fileName, ref missing, ref missing,
ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing);

aDoc.PageSetup.PageHeight = 1050.0F;
aDoc.PageSetup.PageWidth = 710.0F;
aDoc.PageSetup.TopMargin = 5;
aDoc.PageSetup.BottomMargin = 20;
aDoc.PageSetup.LeftMargin = 90;
aDoc.PageSetup.RightMargin = 50;
aDoc.Save();
System.Diagnostics.Process.Start(@path);
Response.End();
}

public void ExpertControl(System.Web.UI.Control source, string File)
{
Response.ContentType = "application/ms-word";
Response.Charset = "utf-8";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
//关闭控件的视图状态
source.Page.EnableViewState = false;
//初始化HtmlWriter
System.IO.StringWriter writer = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter(writer);
source.RenderControl(htmlWriter);
StreamWriter streamwriter = new StreamWriter(File); //创建数据流

streamwriter.Write(writer.ToString()); //输出
streamwriter.Close(); //关闭流
...全文
299 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wzhangjinghai 2012-09-05
  • 打赏
  • 举报
回复
求解中...顶 ,,大鸟给个方案啊
kings2015 2010-01-05
  • 打赏
  • 举报
回复
是不是word文件打开着,关闭它。相关进程也要关闭。建议项目路径不要有中文
生活 2010-01-05
  • 打赏
  • 举报
回复
呵呵 昨天就求救了一天还没解决。
平生我自如 2010-01-05
  • 打赏
  • 举报
回复
帮顶!欧不会了

110,547

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧