I'm getting System.UnauthorizedAccessException when trying to create a file using
using (var fileStream = System.IO.File.Create(filePath))
this is only trace i got
Exception thrown: 'System.UnauthorizedAccessException' in System.Private.CoreLib.dll
It's ASP.NET Core 6 Web API run on docker
Any Ideas? Thanks :)
EDIT: Here is mu complete malfunctioning code snippet:
var filePath = Path.Combine(_environment.WebRootPath, "Uploads");
if(!Directory.Exists(filePath))
Directory.CreateDirectory(filePath);
using (var fileStream = System.IO.File.Create(filePath))
await file.CopyToAsync(fileStream);
Are you trying to create this file into systems folders or similar? Did you try to change your filePath to, let's say your images folder? You need to be sure that you've access rights to write into this folder, otherwise, you might have some issues with Windows permissions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With