How to

set file to ReadOnly state

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

Import namespace

using System.IO;

Code

var info = new FileInfo(@"C:\Folder\test.txt");
info.IsReadOnly = true;

// or

File.SetAttributes(@"C:\Folder\test.txt", FileAttributes.ReadOnly);
Send us feedback about this snippet »



Related Snippets: