Word应用程序在关闭后崩溃并重新打开

时间:2013-06-04 09:53:00

标签: sharepoint interop

我遇到这样一种情况:每当在Sharepoint库中保存新文档(New Document> Save As)时,自定义事件处理程序(ItemAdded)就会触发文档记录的更新并填充一些列值。该文档也是以编程方式签入的。这些更改在单词界面中仍然不可见,因为它在后端触发。我需要从服务器关闭并重新打开文档,以便打开所有服务器属性并更正已检出状态。我使用以下代码关闭并打开:

    Word._Document doc = this.Application.ActiveDocument;
    doc.Close(Word.WdSaveOptions.wdDoNotSaveChanges, System.Type.Missing, System.Type.Missing);
    Word.Document aDoc = this.Application.Documents.Open(docPath, System.Type.Missing, true, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, true, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing);
    aDoc.Activate();

文档正常关闭,但应用程序在打开时崩溃。但是,如果我只从代码中关闭文档并手动从最近的文件列表中打开文档,则文档打开正常。在打开文档之前,我需要做一些清理工作吗?

请注意,我已使用DocumentBeforeSave事件覆盖了word的默认保存操作(Cancel = true)。不确定是否有相关信息。

编辑:我试图捕获上面的块是否存在任何COMException或任何类型的异常,但事实并非如此。它只是在公开声明中崩溃。

1 个答案:

答案 0 :(得分:0)

尝试使用以下内容:

        (new Thread(() =>
        {
            doc.Close(Word.WdSaveOptions.wdDoNotSaveChanges, System.Type.Missing, System.Type.Missing);

        })).Start();