I am writing some C# code which processes a set of files in a source directory and then moves the files to a destination directory. The code must be able to handle a situation in which one of the files might become locked while the files are being processed. I am not concerned at this point with how to handle the exception when a particular file is locked.
What I need to know is how can I lock up the file You see, I must test my code against a file that is locked up. I tried locking up a file by selecting it, and then right clicking on the file and selecting rename. I also tried opening the file for edit. Neither of these two methods will lock up the file.
Can anyone tell me if there is a way to lock up a file

How to lock up a file
Malicious User
Thank you !. Now, conversely, is their a way with C# to progromatically test if a file is locked up by another application
Scott Koo
FileStream fs = File.Open(@"C:\test.txt", FileMode.Open)
and until you don't make fs.Close() in this app, other apps can't use this file.
Dieter Depuydt
JPR7
Jonathan1983