How to remove ReadOnly Attribute from a file?
Hello friends,
Here’s a nice little piece of code you can use to change file attributes of a particular file, its particularly useful when you’re trying to delete a read only file.
string savedCardFilePath = “My absolute file path”;
if (File.Exists(savedCardFilePath))
{
/*
* Remove readonly attribute off of the file if it exists before execution
*
**/
if(File.GetAttributes(savedCardFilePath) == FileAttributes.ReadOnly)
File.SetAttributes(savedCardFilePath, FileAttributes.Normal);
File.Delete(savedCardFilePath);
}
Categories: ASP .NET, C#, Web Development
asp, ASP .NET, C#, File, File Attributes, FileAttributes, GetAttributes, Readonly removal

