Reputation: 479
I am developing a Web Api project with .Net Core. Trying to upload a file using the following code:
string path = Path.Combine(Directory.GetCurrentDirectory(), UploadFolder);
using (var stream = new FileStream(path, FileMode.Create))
{
registration.File.CopyTo(stream);
}
When the line using (var stream = new FileStream(path, FileMode.Create)) is executing, I am getting following Error: "Access to the path 'E:\Dynode\AdminApi Web\Admin Api\ApiService\Upload Folder' is denied". I have given full control to "IIS APPPOOL\DefaultAppPool" and "IIS_Users" objects of the Upload folder.
Upvotes: 0
Views: 493
Reputation: 3113
You need to use a name like 'E:\Dynode\AdminApi Web\Admin Api\ApiService\Upload Folder\file.name
'.
Consider Path.Combine()
to reliably generate the path name.
Or if you are sure your path is ok, change access of your directory like below link:
https://stackoverflow.com/a/28360298/4588756
Upvotes: 1