How to

lock a file

Published: 9. October 2011 | Updated: 31. October 2011
License: Microsoft Public License (MS-PL)
Categories: Windows
Tags: C# File System Windows
Was this snippet helpful for you? YESYES / NONO

Import namespace

using System.IO;

Code

using (FileStream fileStream = File.Open(@"C:\test.txt", FileMode.Open, FileAccess.Read, FileShare.None))
{
    Console.Write("File is locked");
    Console.ReadLine();
}
Send us feedback about this snippet »



Related Snippets: