Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i'm working on a simple windows form application that needs to create a text file in c:\program files\... but i keep running into troubles making the file hidden. I tried
C#
File.SetAttributes(filePath, File.GetAttributes(filePath) | FileAttributes.Hidden)

but it didn't seem to work. Pls can someone help me with the correct code for this.
Posted

check the considered file is not locked and privilege to work with it.

C#
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust")]
private static void SetFileToHidden(string filePath)
{
    var attrs = File.GetAttributes(filePath);
    File.SetAttributes(filePath, attrs | FileAttributes.Hidden);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900