Although the above samples shows you one way of removing the FileAttributes.Hidden attribute, it also, as a side-effect, removes any other attribute (such as FileAttributes.ReadOnly) from the file. The correct way is to only remove the attribute you are interested in.
The following example shows a way of doing this by removing the FileAttributes.ReadOnly attribute.
[C#]
using System;
using System.IO;
namespace Samples
{
class Program
{
static void Main(string[] args)
{
string path = @"C:\Temp\MyTest.txt";
FileAttributes attributes = File.GetAttributes(path);
if ((attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
{
// File is hidden, so remove the hidden attribute
attributes = RemoveAttribute(attributes, FileAttributes.Hidden);
File.SetAttributes(path, attributes);
}
}
private static FileAttributes RemoveAttribute(FileAttributes attributes, FileAttributes attributesToRemove)
{
return attributes & ~attributesToRemove;
}
}
}