Is there any way to lock a file until a browser is closed, the user leaves the current page, or their session expires?
I have a java app that reads annotations from a text file and lets a user modify or add more annotations to a pdf through the java app. Once they do, they click 'save' and the full annotation file is returned to it's original data file.
The issue is that 2 people can open the same annotation file and perform different updates. Then, when each saves, they overwrite the existing file so that only the 2nd user's changes are saved.
The ideal solution is to let 1 person 'check-out' the file for edit, make their modifications until either they close the window, navigate away from the page, or their session expires, then the file would automatically 'check-in'. Any way of doing this in C#? Thanks!
Well is there is no simple built in way to do this , what you can do is create a {username}.lock file in the same folder as the annotations folder. Then before you read or save check if there is a .lock file in the directory.
If there is a file tell the user its been locked and can not be updated. Obviously you need to make sure that you delete the .lock file otherwise after first access no one will ever be able to access the annotations file.