How to set a .txt file to hide C# 2.0

How can you set the properties of a .txt file to hidden


Answer this question

How to set a .txt file to hide C# 2.0

  • spshah

    That was very helpful. Is it the same for folders as well

  • Mike Haro

    For the most part... only you use DirectoryInfo instead.

  • Zeldacat

    It's as easy as setting the FileAttributes property of a FileInfo class that references the file ala:

    FileInfo fi = new FileInfo(@"C:\Some Dir\Some Text File.txt");

    //Add Hidden flag (using bitwise ORing to leave any other values in place)

    fi.Attributes = fi.Attributes | FileAttributes.Hidden;

    //Remove Hidden flag if it is checked

    if ((fi.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)

    {

    //using bitwise XORing to leave any other values in place and remove only the Hidden flag

    fi.Attributes = fi.Attributes ^ FileAttributes.Hidden;
    }



  • How to set a .txt file to hide C# 2.0