Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
&lt;<code>&lt;&lt;&lt;&lt;&lt;&lt;</code>&lt;
Posted
Updated 21-May-23 7:12am
v2

You can't.
The file is locked because it has been opened: it is in use.
The most common reason for this is that your own app has opened the file, and failed to close and dispose the file stream correctly. The file then remains in use until the garbage collector disposes the stream automatically, or the app ends.
 
Share this answer
 
Comments
Mehdi Gholam 23-Sep-11 3:34am    
my 5!
Unlocking the file can be done by the locker.

To access the file share it with other processes (including the original), try it by specifying the FileShare mode ReadWrite.

Using myFile As FileStream = New FileStream(ediWatchedFile.Text, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)


For example, it works on a VirtualBox COM port redirected to a file.

How to Read Locked file in VB or C# - BinaryWorld Blog[^]

FileShare Enum (System.IO) | Microsoft Learn[^]
 
Share this answer
 
Comments
Richard Deeming 22-May-23 3:50am    
Your almost 12 years too late, and basically repeating what has already been said.

And resurrecting an old question to link to a blog looks suspiciously like spam.
Peter Adam 22-May-23 4:35am    
Sorry, I just had the same question, found this "answer", and was able to solve my problem. Well, if you want to read from the locked file, you probably can do it. If you want to write into it, then out of luck. OP did not specify why he/she wanted to unlock the file.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900