
[英]HTML/JQuery: How to close browser tab automatically after word document download (ms-word:ofe|u|)?
[英]Word application crashes after close and reopen
我遇到的情况是,每当新的新文档(“新文档”>“另存为”)保存到Sharepoint库中时,自定义事件处理程序(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事件(Cancel = true)覆盖了word的默认保存操作。 不知道那是否是相关信息。
编辑:我试图捕获上述块是否引发任何COMException或任何种类的异常,但事实并非如此。 它只是在open语句上崩溃。
尝试使用以下内容:
(new Thread(() =>
{
doc.Close(Word.WdSaveOptions.wdDoNotSaveChanges, System.Type.Missing, System.Type.Missing);
})).Start();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.