// File Attributes [C#] string filePath = @"c:\test.txt"; // get file attributes FileAttributes fileAttributes = File.GetAttributes(filePath); Set file attributes To set file attributes use static method File.SetAttriĀ­butes. Parameter of the method is a bitwise combination of FileAttributes enumeration. // clear all file attributes File.SetAttributes(filePath, FileAttributes.Normal); // set just only archive and read only attributes (no other attribute will set) File.SetAttributes(filePath, FileAttributes.Archive | FileAttributes.ReadOnly); // check whether a file is read only bool isReadOnly = ((File.GetAttributes(filePath) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly); // check whether a file is hidden bool isHidden = ((File.GetAttributes(filePath) & FileAttributes.Hidden) == FileAttributes.Hidden); // check whether a file has archive attribute bool isArchive = ((File.GetAttributes(filePath) & FileAttributes.Archive) == FileAttributes.Archive); // check whether a file is system file bool isSystem = ((File.GetAttributes(filePath) & FileAttributes.System) == FileAttributes.System); // set (add) hidden attribute (hide a file) File.SetAttributes(filePath, File.GetAttributes(filePath) | FileAttributes.Hidden); // set (add) both archive and read only attributes File.SetAttributes(filePath, File.GetAttributes(filePath) | (FileAttributes.Archive | FileAttributes.ReadOnly)); Delete/clear file attributes from current ones To delete file attributes from the existing ones get the current file attributes first and use AND (&) operator with a mask (bitwise complement of desired attributes combination). // delete/clear hidden attribute File.SetAttributes(filePath, File.GetAttributes(filePath) & ~FileAttributes.Hidden); // delete/clear archive and read only attributes File.SetAttributes(filePath, File.GetAttributes(filePath) & ~(FileAttributes.Archive | FileAttributes.ReadOnly));