File Locking a Text File on a Network Drive
I haven't figured out how to successfully implement file locking, and hope someone has ideas on how I can do it.
I've got a text file on a shared drive that anyone can access through a VB program I've authored. What we've seen is that if someone is already in the text file (such as me testing new functionality!), someone else will submit data to the text file through the program, but their changes are lost (because someone is already in the file).
An example of what I'm looking for is how Microsoft handles Word or Excel files. If someone is already in a file and another user tries to open it, they receive a message stating the file is in use and that they can view it as read-only or be notified when the file is available.
Does anyone know of a good solution to this problem?
Thanks in advance for your help!
Take a look at the optional parameters on VB's Open statement. You can open a file for Shared access, allowing other users to access it simultaneously. You can Lock an entire file for Read or Write access, so that other users cannot read or write until you close the file. Or you can use the Lock statement to lock a specific range of bytes in the file.
You will also need to add error handling, so that if your program attempts to access the file while it is locked, you can trap the error and display a "friendly" message to the user.
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL