Can VB.NET read file even if it is locked by another application?

Try this example.

1. Open a file in MS Word (Word locks the file).
2. Use 'Open With' and open the same file in Notepad (it works)
3. In VB.NET, I've tried File.ReadAllText, File.OpenRead and File.Open with read access and it says the file is locked.

If Notepad can open a file even if it is locked, surely there must be a way to do in VB.NET...

Does anyone know?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

yer I got caught on this also..

you need to allow the other application to write also to it so the share option is FileShare.ReadWrite.

Dim oFS As IO.FileStream = Nothing
Dim oFSt As IO.StreamReader = Nothing
oFS = New IO.FileStream(sPath & sLogFile, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.ReadWrite)  <--- FileShare.ReadWrite.
oFSt = New IO.StreamReader(oFS)
Dim s As String = oFSt.ReadLine


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.