C# .NET - How Can I Lock a Directory While Updating Its Contents?

Asked By Jon Shipman on 22-Apr-08 11:49 AM

In my application, files are reviewed and when they are approved the app puts the files and an xml describing the files in a directory.  The files and the xml are then retrieved and moved by a person.

When updating the directory contents, I'd like to lock the directory, update the xml file and copy the files in, then unlock it.  I have to ensure that a person doesn't grab files or the xml when they aren't in sync.

Any suggestions?

The only way you can "lock" a folder

Peter Bromberg replied to Jon Shipman on 22-Apr-08 03:47 PM
is to temporarily change the ACL's (access permissions) on it. You can do that in managed code, but maybe it's time to re-think the whole process and move stuff to a Database so it will be easier to handle the workflow rules.

RE

Swapnil Salunke replied to Peter Bromberg on 25-Apr-08 12:38 AM

Hello

As Peter says its correct. Or else If you can able to lock the handle of the directory being used by your application that would be much easier. using Lock(Object O) You can lock the handler so others can get the Window Prompted Message of File Being used

Happy Coding

Takecare