I'm trying to copy files from a client to a server that has a shared drive. When I do that I get the UnauthorizedAccessException
and it says access denied to this path I'm trying to copy to. This is very odd since I have all the permissions and I am logged in as the administrator. The weird thing is that when writing to a text file on the same path on the server it works. Like this:
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();
}
But when doing the copy method I get this exception. Here is how I copy:
FileInfo file = new FileInfo(sourcePath);
string newPath = targetPath + "\\" + file.Name;
File.Copy(sourcePath, newPath, true);
So I enter the whole path with the filename and extension for both source and target.
I've tried stuff like "File.SetAttributes(dest, FileAttributes.Normal);
", and everything on the server, like security on the map etc.
Do you have a clue what's wrong? I would appreciate your help alot!
Thanks in advance