Open file for reading

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

Hi,

I want to open a file for read-only mode. I tried using a
StreamReader and this works, but it throws an exception
when the file is already open by another process. I think
it should be okay to open a file in read-only mode. Does
anyone know how to do this?

Thanks,
Paul
 
You could try opening the file manually, that way you can specify the access
modes. Then pass the stream into the StreamReader.
 
Thanks Peter. I tried that before I posted my question. It didn't work. I
get an IOException when I try to read.
 
Have you checked to make sure that the process that already has the file
open doesn't have a read lock on it? You could be doing everything
correctly, but if a previous program opens the file with concurrent read
denied you'll have no luck.
 
Back
Top