我如何打开在另一个应用程序打开的文件 [英] How do I open a file that is opened in another application

查看:181
本文介绍了我如何打开在另一个应用程序打开的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WinForms应用程序中的Excel文件进​​行分析的载荷。目前,为了打开Excel文件中的文件不能在Excel中,否则当我尝试和文件中加载一个FileIOException被抛出已经打开。

I have an winforms application that loads in excel files for analysis. Currently, in order to open the excel file the file must not be already open in excel otherwise a FileIOException is thrown when I try and load in the file.

我想要做的就是让我的应用程序在文件中读取,即使是在Excel中打开,而不是强迫用户首先关闭工作表。需要注意的是有问题的应用程序只需要读取的文件,而不是写它。

What I would like to do is allow my application to read in the file even if it is open in excel rather than forcing the user to close down the worksheet first. Note that the application in question only needs to read the file, not write to it.

这可能吗?

推荐答案

在打开文件时,你可以尝试通过FileShare.ReadWrite:

You could try passing FileShare.ReadWrite when opening the file:

using (var stream = new FileStream(
       @"d:\myfile.xls", 
       FileMode.Open, 
       FileAccess.Read, 
       FileShare.ReadWrite))
{

}

这篇关于我如何打开在另一个应用程序打开的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆