Everything in Particular

September 5, 2007

Clearing the read-only flag on a file in C#

Filed under: Development — omatase @ 4:58 pm

[code lang="c#"]
FileInfo myFile = new FileInfo("c:\\myfile.txt");

if ((myFile & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
{
// remove the read only attribute
myFile.Attributes = (FileAttributes)(Convert.ToInt32(myFile.Attributes) - Convert.ToInt32(FileAttributes.ReadOnly));
}
[/code]

Powered by WordPress