Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I open a file that is opened in another application

Tags:

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.

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.

Is this possible?

like image 965
Calanus Avatar asked Jun 26 '09 09:06

Calanus


People also ask

Why does it say the file is open in another program?

The error “File is open in another program” occurs when you perform an operation on a file but because the file is being accessed by another program, you are not able to execute tasks or operations on it.

How do you get the files that are opened by an application?

To see the open files for a process, select a process from the list, select the View->Lower Panel View->Handles menu option. All of the handles of type "File" are the open files. Also, a great way to find which application has a file open is by using the Find->Handle or DLL menu option.

What to do when it says another program is using this file?

Close Programs Running in the Background The quickest way to see what programs are running on your computer is to launch the Task Manager. Then click on the Processes tab. Right-click on the program that's using that file and select End Task to close it.


1 Answers

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

using (var stream = new FileStream(        @"d:\myfile.xls",         FileMode.Open,         FileAccess.Read,         FileShare.ReadWrite)) {  } 
like image 89
Darin Dimitrov Avatar answered Sep 28 '22 08:09

Darin Dimitrov