a blog for those who code

Thursday 26 June 2014

Hide or Unhide the file in C#

The below code snippet will help you to make a file hidden if its not and unhide the file if its hidden.


Get File Attributes

FileAttributes attributes = File.GetAttributes("YOUR_FILE_PATH");

If you want to unhide the file use the below code...

if((attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
{
attributes = RemoveAttributes(attributes, FileAttributes.Hidden);
File.SetAttribute = ("YOUR_FILE_PATH", attributes);
}

If you want to hide the file use the below code...

File.SetAttribute = ("YOUR_FILE_PATH", File.GetAttributes("YOUR_FILE_PATH") | FileAttributes.Hidden);

Please like and share the blog if you find it interesting and helpful.

No comments:

Post a Comment