I have a weird issue with my computer.
I cannot use my C# apps to rename or delete files on my desktop and in other specific directories on my computer.
There's no real pattern and the information is below:
using System;
using System.IO;
namespace justATest
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
string path = @"C:\Users\USERNAME\Desktop\";
string nameBefore = Path.Combine(path, "test.txt");
string nameAfter = Path.Combine(path, "something.txt");
File.Move(nameBefore, nameAfter); // Fails
}
}
}
The exception:
System.UnauthorizedAccessException
HResult=0x80070005
Message=Access to the path is denied.
Source=System.IO.FileSystem
StackTrace:
at System.IO.FileSystem.MoveFile(String sourceFullPath, String destFullPath, Boolean overwrite)
at System.IO.File.Move(String sourceFileName, String destFileName, Boolean overwrite)
at System.IO.File.Move(String sourceFileName, String destFileName)
at justATest.Program.Main(String[] args) in C:\Users\USERNAME\source\repos\justATest\justATest\Program.cs:line 16
What I tried:
- I updated Windows to the latest version
- I checked the file's owner
- I checked the file's permissions
- I ran my app as an administrator
- I ran Visual Studio as an administrator
- I ran SFC /ScanNow
- I did some kind of a repair to my Windows installation (through Microsoft Support)
- I created multiple files and tried it on old and new files
- I created nested folders and tried to rename files within said folders
10. I tried renaming files in other directories (that works)
11. I tried the method of copying the file into a new file (with the new name) and then deleting the old file. This works until I try to delete the old file, which fails
12. I tried doing the same tasks manually and it works just fine
13. I tried turning off my anti virus
14. I tried to repair Visual Studio
I mainly want to rename files, but the same goes for deleting files and the like.
OS: Windows 10 Pro 21H2
IDE: Visual Studio 2019 16.11.15
Number of users on machine: 1 (just me)
If you need any more information, let me know.
P.S.: I was sent here after the Microsoft chat support could not solve my issue through various methods (they even made me repair my Windows installation).
I'm honestly clueless.