Im trying to make file named hello.txt and code show error that I dont have access to the path.
So how can I make file?
Code:
static void create_file(string path)
{
FileStream fs = File.Create(path);
}
static void Main(string[] args)
{
create_file("hello.txt");
}
Error:
System.UnauthorizedAccessException
HResult=0x80070005
Message=Access to the path 'C:\Users\user\Desktop\Bored\Bored\bin\Debug\netcoreapp3.1\hello.txt' is denied.
Source=System.Private.CoreLib
StackTrace:
at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
at System.IO.File.Create(String path)
at Bored.Program.create_file(String path) in C:\Users\user\Desktop\Bored\Bored\Program.cs:line 56
at Bored.Program.Main(String[] args) in C:\Users\user\Desktop\Bored\Bored\Program.cs:line 61