Reading a text file with StreamReader

  • Thread starter Thread starter km
  • Start date Start date
K

km

I have a tab delimited text file that I open in Excel.
While it is open in Excel I need to open and read it from my C# application.
I get an access error opening the file with StreamReader or File.Open
The error message says that another application has the file open (which of
course I already knew).

Notepad can open the file while it is open in Excel. Why can't the framework?

I've tried specifying the access as read-only, no luck.

Any suggestions would be appreciated.
 
When I say "try", I mean, I have no idea if it'll work or not.

Excel is obviously putting a lock on the file.
Check the "Open As" options under Excel, if they exist.
 
in km wrote :
I have a tab delimited text file that I open in Excel.
While it is open in Excel I need to open and read it from my C#
application. I get an access error opening the file with StreamReader
or File.Open

Did you try to use a FileStream instead of a path in the StreamReader
constructor ?
Many options exist when creating a FileStream.
In this way I don't get your error.
 
Back
Top