I tried to create a file with File.Create but I get an error. I can't fix that. I searched for this problem and found this code and I copied it to Visual Studio but it still has this error :
An unhandled exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll
Additional information: Access to the path 'C:\aaa.txt' is denied.
My code:
string path = "C:\\aaa.txt";
if (File.Exists(path))
{
Console.WriteLine("file exist");
}
else
{
using (FileStream fs = File.Create(path))
{
Byte[] info = new UTF8Encoding(true).GetBytes("This is some text in the file.");
fs.Write(info, 0, info.Length);
}
}