[Last Call] Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2006-04-15
Medium Priority
Last Modified: 2010-04-23
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?
Question by:khooc
1 Comment
LVL 11

Accepted Solution

coopzz earned 1200 total points
ID: 16466930
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


Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question