c# FileLock – If you need to lock a file for temporary purpose.
23/01/2012 Leave a comment
Hi Everyone ,
FileLock is vey simple tool that locking defined file in given path. This tool can be used acting as AV programs , troublesoothing or reproduce error when a file is locked scenarios .
You can download binaries or source from :
http://spstools.codeplex.com/releases/view/80978
- class Program
- {
- static void Main(string[] args)
- {
- if (args.Length != 1)
- {
- Console.WriteLine(“FileLock v1.0”);
- Console.WriteLine(“Usage: FileLock <path>”);
- }
- else
- {
- Console.WriteLine(args[0] + ” is Locked” + Environment.NewLine + “Press any key to relase!”);
- using (FileStream fs = new FileStream(args[0], FileMode.Open, FileAccess.Write, FileShare.Write))
- {
- fs.Lock(0, fs.Length);
- Console.ReadKey();
- fs.Unlock(0, fs.Length);
- }
- }
- }
- }