MrNobody,
What you want to do is use the FileStream constructor which takes a
FileAccess (with the Read value) and the FileShare value of ReadWrite (most
likely). Chances are something else is writing to the file and if you don't
specify that you can share it to write (and something is already trying to
write) then you are going to be denied access.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"MrNobody" <Mr******@discussions.microsoft.comwrote in message
news:BC**********************************@microsof t.com...
>I was writing a program that was reading data from files (not making any
changes) and I used the File.OpenRead(filename) command. It threw an error
for one file because it said the file was being used by another process.
But
I can open this file fine with Notepad and see the contents.
How can I open the file without trying to get a lock on it, since I just
want to read it? I would have imagine OpenRead would do that but it
obviously
isn't.