Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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) 
like image 827
MilMike Avatar asked Sep 13 '11 09:09

MilMike


People also ask

How do I remove Read-Only attribute?

Remove the read-only attribute Some read-only files can be changed to allow for edits by removing the read-only attribute in the file properties. Right-click the file and select Properties. Uncheck the box for Read-only and click OK.

How to remove ReadOnly attribute from file c#?

To Remove ReadOnly Attribute , We Have To Use FileInfo Class & By Using IsReadOnly = false , We Can Remove ReadOnly Attribute.

What is read-only attribute?

The readonly attribute is a boolean attribute. When present, it specifies that an input field is read-only. A read-only input field cannot be modified (however, a user can tab to it, highlight it, and copy the text from it).


1 Answers

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.

like image 129
sll Avatar answered Oct 14 '22 07:10

sll