C# update FileAttributes
System.UnauthorizedAccessException: 'Access to the path 'D:\C\ConsoleApp13\bin\Debug\net8.0\ConsoleApp13.deps.json' is denied.'
static void Main(string[] args) { string filePath = "ConsoleApp13.deps.json"; UpdateFileAttributeReadonlyToArchive(filePath); PrintLog(); } static void UpdateFileAttributeReadonlyToArchive(string filePath=null) { if(File.Exists(filePath)) { FileAttributes fa = File.GetAttributes(filePath); if ((fa & FileAttributes.ReadOnly) != 0) { fa ^= FileAttributes.ReadOnly; File.SetAttributes(filePath, fa); } File.Delete(filePath); } }