Sharepoint Word应用程序在关闭和重新打开后崩溃
我遇到的情况是,每当在Sharepoint库中保存新文档(新建文档>另存为)时,自定义事件处理程序(ItemAdded)都会对文档记录进行更新,并填充一些列值。此外,该文档也是按程序签入的。这些更改在word界面中保持不可见,因为它在后端触发。我需要从服务器上关闭并重新打开文档,以便打开文档时包含所有服务器属性和正确的签出状态。我使用以下代码来关闭和打开:Sharepoint Word应用程序在关闭和重新打开后崩溃,sharepoint,interop,Sharepoint,Interop,我遇到的情况是,每当在Sharepoint库中保存新文档(新建文档>另存为)时,自定义事件处理程序(ItemAdded)都会对文档记录进行更新,并填充一些列值。此外,该文档也是按程序签入的。这些更改在word界面中保持不可见,因为它在后端触发。我需要从服务器上关闭并重新打开文档,以便打开文档时包含所有服务器属性和正确的签出状态。我使用以下代码来关闭和打开: Word._Document doc = this.Application.ActiveDocument; doc.Clos
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事件(Cancel=true)覆盖了word的默认保存操作。不确定这是否是相关信息
编辑:我试图捕捉上面的块是否有任何COMException或任何类型的异常,但它没有。它只是在open语句上崩溃。请尝试使用以下命令:
(new Thread(() =>
{
doc.Close(Word.WdSaveOptions.wdDoNotSaveChanges, System.Type.Missing, System.Type.Missing);
})).Start();