Friday, February 5, 2010

Programmatically hide a file with C#

If you want to hide a file or folder, you need to use the System.IO.FileAttributes library, see the example below:

string filePath = @"C:\MyFile.txt";
System.IO.FileInfo f = new System.IO.FileInfo(filePath);
f.Attributes = System.IO.FileAttributes.Hidden;
Console.WriteLine("You can not see the file!");

You can do a lot more things with the library System.IO.File, like copy, move, etc.
This example also works with the .Net Compact Framework





No comments:

Post a Comment