我正在尝试将文件从客户端复制到具有共享驱动器的服务器。当我这样做时,我得到了UnauthorizedAccessException
它,它说拒绝访问我试图复制到的这条路径。这很奇怪,因为我拥有所有权限并且我以管理员身份登录。奇怪的是,当写入服务器上同一路径上的文本文件时,它可以工作。像这样:
FileStream fs = new FileStream(@"\\SIMON-VAIO\SimonShared\Users\Simon\Desktop\Files\Clients\clients.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using (StreamReader sr = new StreamReader(fs))
{
while (sr.Peek() >= 0) //as long as there are characters to read
{
ListViewItem lvwItem = new ListViewItem();
lvwItem.Text = sr.ReadLine();
AddListViewItem(lvwItem);
}
sr.Close();
}
但是在执行复制方法时,我得到了这个异常。这是我复制的方式:
FileInfo file = new FileInfo(sourcePath);
string newPath = targetPath + "\\" + file.Name;
File.Copy(sourcePath, newPath, true);
所以我输入了源和目标的文件名和扩展名的整个路径。
我已经尝试过诸如“ File.SetAttributes(dest, FileAttributes.Normal);
”之类的东西,以及服务器上的所有内容,例如地图上的安全性等。
你知道出了什么问题吗?非常感谢您的帮助!
提前致谢