c# - Prevent a user from deleting, moving or renaming a file -


what trying while program using file, want keep user renaming, deleting, or moving file (well... move delete , create @ different location according windows filesystemwatcher, digress).

it has been suggested use filestream.lock or use mutex. however, filestream.lock seems prevent file being modified which trying allow. also, unsure if mutex can lock file, although still reading on in .net 4.0 library.

does have advice on utilizing either 1 , if there code based solution problem?

when opening file, can specify sharing mode.

opening file fileaccess.read gives ability read file, while fileshare.readwrite allows file continue edited, not deleted or moved.

var fs = file.open(@"c:\temp\file.txt", filemode.open, fileaccess.read, fileshare.readwrite); messagebox.show("file locked");  // while messagebox up, try open or delete file. // work here fs.close(); 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -