使用.NET Core 2.0创建目录可以在文件系统中成功创建目录,但是我无法对其进行写入。
var downloadPath = Path.Combine(DownloadPath, "Target");
var downloadDirectory = Directory.CreateDirectory(downloadPath); // Succeeds
DownloadMultipleFilesAsync(zoneFileUrls, downloadPath); // Fails
当执行DownloadMultipleFilesAsync
方法时,我最终收到以下错误。如果我从目录属性中删除FileAttributes.ReadOnly
并不重要,它仍然会出现此错误。
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
通过Visual Studio运行它。在“文件资源管理器”中,我以目录的所有者身份查看我的名字,因此我知道控制台应用程序正以我的身份运行,因此不确定为什么它不允许我将文件下载到其中。
答案 0 :(得分:0)
请确保该文件夹对IIS_IUSRS和IUSR用户组具有正确的权限。仅出于测试目的,您可以在父文件夹上为“所有人”设置完全访问权限。
答案 1 :(得分:0)
我忘记将文件名附加到路径:-(