问题描述
如何禁用的提示,而使用的Microsoft.Office.Interop.Word打开Word文件。提示符如下:Test.doc的锁定由其他用户编辑。你想要_____吗: 。开一个只读副本 .Create本地副本,后来合并更改。 当原始副本可用.Receive通知。
How to disable prompt while opening word file using Microsoft.Office.Interop.Word.Prompt is as follows:Test.doc is locked for editing by another user.Do you want to: .Open a read only copy .Create a local copy and merge your changes later. .Receive notification when the original copy is available.
推荐答案
如果您不需要修改,你可以打开它只读通过word.document.open方法的文档,设置第三个参数设置为true。
If you don't need to modify the document you could open it as read only through the word.document.open method, setting the third parameter to true.
如果你需要打开它进行编辑,你可以在防守code。通过测试,以查看是否有试图打开它之前的Word文档文件锁定。实现这样的一个选择可能是,如果抛出这将表明您不能编辑它在一个FileStream对象打开文件进行写访问和陷阱异常。然后你会使用这些信息来决定是否打开只读或编辑你的code。
If you do need to open it for editing you could code defensively by testing to see if there was a file lock on the word document before attempting to open it. An option to implement this might be to open the file in a filestream object for write access and trap an exception if thrown which would indicate you cannot edit it. You'd then use this information to decide whether to open readonly or for editing in your code.
这篇关于禁用提示当读取.doc文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!