File Locking a Text File on a Network Drive


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: File Locking a Text File on a Network Drive

  1. #1
    Join Date
    Apr 2005
    Location
    Jacksonville, FL
    Posts
    17

    Question File Locking a Text File on a Network Drive

    Hi everyone,

    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!

    -- Miles

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    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.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center