Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 关闭Word文档时出错:“文件”;消息筛选器指示应用程序正忙。”;_C#_Asp.net_Com Interop - Fatal编程技术网

C# 关闭Word文档时出错:“文件”;消息筛选器指示应用程序正忙。”;

C# 关闭Word文档时出错:“文件”;消息筛选器指示应用程序正忙。”;,c#,asp.net,com-interop,C#,Asp.net,Com Interop,我正在使用Microsoft Interop将Word文档保存为HTML文件,在尝试关闭文档时出现以下错误: 消息筛选器指示应用程序正忙。(HRESULT的例外:0x8001010A(RPC_E_服务器调用_RETRYLATER)) 这是我的密码: // word interop setting object visible = true; object readOnly = true; object missing = Type.Missing; object saveChanges = tr

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

消息筛选器指示应用程序正忙。(HRESULT的例外:0x8001010A(RPC_E_服务器调用_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;
}

有人知道我做错了什么吗?

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

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

有关更多信息:


但是,您可以在不启动office的情况下使用该类来处理office文档。

在我测试它时,它工作正常,您确定您的html文件路径正确吗?我做了一个控制台应用程序,只在本地保存这两个文件,它的工作没有问题。可能您在试图保存的位置方面遇到了安全问题?这应该是一个注释imo@kd7我的答案太长了81个字符。我在Excel到PDF转换(通过Office互操作程序集)时也遇到了同样的问题。我最终实现了这里提到的解决方案:。请注意,coRegisterMessageFilter()API将仅在STA线程上工作,并在MTA线程上失败。因此,如果无法更改当前客户端线程的单元类型,则需要启动一个新的单元类型(STA!),并等待它完成(thread.Join())。