Creating a directory with .NET Core 2.0 successfully creates a directory in the file system but I am unable to write to it.
var downloadPath = Path.Combine(DownloadPath, "Target");
var downloadDirectory = Directory.CreateDirectory(downloadPath); // Succeeds
DownloadMultipleFilesAsync(zoneFileUrls, downloadPath); // Fails
I end up getting the following error when the DownloadMultipleFilesAsync
method is executed. It does not matter if I remove FileAttributes.ReadOnly
from the directory attributes, it still gives this error.
System.Net.WebException: An exception occurred during a WebClient request. ---> System.UnauthorizedAccessException: Access to the path 'D:\Projects\ETL\My.ETL\bin\Debug\netcoreapp2.0\Work\Target' is denied.
at SafeFileHandle System.IO.FileStream.OpenHandle(FileMode mode, FileShare share, FileOptions options)
at new System.IO.FileStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options)
at new System.IO.FileStream(string path, FileMode mode, FileAccess access)
at void System.Net.WebClient.DownloadFileAsync(Uri address, string fileName, object userToken)
--- End of inner exception stack trace ---
at async Task My.ETL.Services.FileProviders.FileProvider.DownloadFileTaskAsync(string url, string downloadPath) in D:\Projects\ETL\My.ETL.Services\FileProviders\FileProvider.cs:line 80
Running this through Visual Studio. In File Explorer I see my name as the owner of the directory so I know the console app is being run as me so not sure why it will not let me download files into it.