I'm debugging my NetCore 3.1 project in Visual Studio 2019. I am doing this locally using the built-in IIS Express on Windows 10.
I am trying to save files to my D: drive.
I'm getting the error below when I try to copy a file to the local file system when running my Visual Studio project in debug mode using IIS Express:
{"Access to the path 'D:\\biologyMedia\\eb4cf4c2-6434-4cfe-9fa8-0033bc9b1a08' is denied."}
The error happens in the method below in the try block:
public async Task<bool> CopyFile(IFormFile examFile, Guid diseaseId)
{
string path = @"D:\biologyMedia\" + diseaseId + @"\";
if (!Directory.Exists(path))
{
DirectoryInfo di = Directory.CreateDirectory(path);
}
try
{
using (var fileStream = new FileStream(path, FileMode.Create))
{
await examFile.CopyToAsync(fileStream);
}
} catch (Exception e)
{
var error = e.InnerException;
return false;
}
return true;
}
Based on previous answers, I've tried the following:
I'm not sure what else I can try.
Anyone ever fix this before?
Thanks!
Skye, sorry, but could it be that your path in
using (var fileStream = new FileStream(path, FileMode.Create))
{
await examFile.CopyToAsync(fileStream);
}
is actually the folder @"D:\biologyMedia\" + diseaseId + @"\"; and therefore not a filename?
So you are trying to copy a file ONTO a folder not INTO it?