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)
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.
To Remove ReadOnly Attribute , We Have To Use FileInfo Class & By Using IsReadOnly = false , We Can Remove ReadOnly 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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With