关闭Word文档时出错:“邮件过滤器指示应用程序正忙。”

时间:2012-12-21 18:22:02

标签: c# asp.net com-interop

我正在使用Microsoft Interop将Word文档保存为HTML文件,当我尝试关闭文档时出现此错误:

  

消息过滤器指示应用程序正忙。 (来自HRESULT的异常:0x8001010A(RPC_E_SERVERCALL_RETRYLATER))

这是我的代码:

// word interop setting
object visible = true;
object readOnly = true;
object missing = Type.Missing;
object saveChanges = true;
object htmlFile = (object)Server.MapPath(@"worddoc.html");
object fileType = 
  (object)Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatFilteredHTML;       

// open document
Microsoft.Office.Interop.Word.Application wordApp =
  new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document wordDoc =
  wordApp.Documents.Open(ref url, ref missing, ref readOnly, ref missing,
       ref missing, ref missing, ref missing, ref missing, ref missing,
       ref missing, ref  missing, ref  visible, ref missing, ref missing,
       ref missing, ref missing);

try
{                           
    // save the file                 
    wordDoc.SaveAs(ref htmlFile, ref fileType, 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);
}
catch (System.Exception ex)
{
    saveChanges = false;
}
finally
{
    wordDoc.Close(ref saveChanges, ref missing, ref missing); // ERROR HERE
    wordApp.Quit(ref saveChanges, ref missing, ref missing);
    wordDoc = null;
    wordApp = null;
}

任何人都知道我做错了什么?

1 个答案:

答案 0 :(得分:6)

您的代码没有任何问题。问题是你在不支持的配置中运行它,并且在这种情况下(在asp.net下运行)未定义office的行为

  

Microsoft目前不推荐,也不支持,   任何无人值守的Microsoft Office应用程序的自动化,   非交互式客户端应用程序或组件(包括ASP,   ASP.NET,DCOM和NT服务),因为Office可能会出现不稳定   Office在此环境中运行时的行为和/或死锁。

欲了解更多信息:

http://support.microsoft.com/kb/257757

但是,您可以使用VSTO server document课程来处理Office文档而无需启动Office。