我正在使用 FileStream 将 FTP 服务器的信息下载到我的 C:\驱动器上的目录中。由于某种原因,即使我什至尝试将目录权限设置为“每个人”访问权限,它还是给了我这个异常(exception):
System.UnauthorizedAccessException: Access to the path 'C:\tmpfolder' is denied'
这是为什么呢?这是我的代码的摘录。
byte[] fileData = request.DownloadData(dataMap.GetString("ftpPath") + "/" + content);
file = new FileStream(@"C:\tmpfolder", FileMode.Create, FileAccess.Write);
downloadedlocation = file.ToString();
file.Write(fileData, 0, fileData.Length);
此外,我的程序不在 ASP.NET 中,而只是一个 C# 控制台应用程序。
最佳答案
如果存储文件的位置并不重要,请尝试
using System.IO;
.
.
.
string tempFile = Path.GetTempFileName();
这将在您的帐户临时文件夹中创建一个临时文件。不用担心权限问题;-)
关于c# - FileStream 不允许我在本地计算机上创建文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4014994/