If you are using a database, you can create a table with filenames and statuses. when a file is first opened, you can set the status to locked. For subsequent attempts, you can check the status of the file and if it's open, go for it! Otherwise, show an error, or some such.....