Everything in Particular

September 5, 2007

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

Filed under: Development — omatase @ 4:58 pm
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));
}

2 Comments »

  1. myFile.Attributes -= FileAttributes.ReadOnly; works as well

    Comment by Scott — August 26, 2008 @ 8:24 am

  2. awesome input, thanks Scott!

    Comment by omatase — August 26, 2008 @ 10:37 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress