How to remove a single Attribute (e.g. ReadOnly) from a File?

MilMike picture MilMike · Sep 13, 2011 · Viewed 93.5k times · Source

Let say, a file has the following attributes: ReadOnly, Hidden, Archived, System. How can I remove only one Attribute? (for example ReadOnly)

If I use the following, it removes all the attributes:

IO.File.SetAttributes("File.txt",IO.FileAttributes.Normal)

Answer

sll picture sll · Sep 13, 2011

Answering on your question in title regarding ReadOnly attribute:

FileInfo fileInfo = new FileInfo(pathToAFile);
fileInfo.IsReadOnly = false;

To get control over any attribute yourself you can use File.SetAttributes() method. The link also provides an example.