2

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.

Adam
  • 4,590
  • 10
  • 51
  • 84
  • Hello, Have you tried to append the permissions on the Directory from the C# Code while creating the directory ? While using .net core 2 you might using kestrel as well and require separate permissions. – Nick Polyderopoulos Oct 06 '18 at 21:28

2 Answers2

5

I forgot to append the file name to the path :-(

Adam
  • 4,590
  • 10
  • 51
  • 84
0

Please make sure that folder has correct permissions for IIS_IUSRS and IUSR users groups. Just for testing purposes, you can set Full Access permissions for Everyone user on the parent folder.

  • I've verified both of those have Full Control permissions in addition to every other group listed. Still gives the same error. – Adam Oct 06 '18 at 20:29