I wrote a recursive function using System.IO stuff in order to copy a directory and all its contents to another location. I'm using Windows 7 and Visual C# 2010.
It looked like a simple task but it really isn't. First, when i tried to run the code i got a permission error. Much research told me that to fix this i had to change the manifest to request better permissions, so i set it to ask for highestAvailable thinking this would surely work.
I was wrong. Next I got an error about my program being a clickonce application that shouldn't recieve rights. Told the IDE that this wasn't a clickonce app.
This caused the program to run but and an UnauthorisedAccessException was thrown by System.IO.File.Copy. I restarted the IDE, this time opening it as Administrator. Same thing happened.
The next thing i tried was setting uiAccess to true in the manifest. Now when i try to build i get a cryptic error message with a broken help link. It says running an Accessability application requires following the steps shown in help (the broken link)
I refuse to believe that simply copying a file should be this difficult. Has anybody managed? You will earn serious hero points if you can tell me how
the function is below. There's some stuff missing but it should be simple to follow my logic:
void copyContents(string source,string dest)
{
if (Directory.Exists(source))
{
Console.WriteLine("source located. copy commenced");
if (!Directory.Exists(dest))
System.IO.Directory.CreateDirectory(dest);
//now we copy each file inside
string[] files = System.IO.Directory.GetFiles(source);
string filename;
foreach (string s in files)
{
filename = System.IO.Path.GetFileName(s);
dest = System.IO.Path.Combine(dest, filename);
System.IO.File.Copy(source, dest, true); //strange error here
}
//next we copy each folder inside
string[] dirs = System.IO.Directory.GetDirectories(source);
//to do
}
else
Console.WriteLine("invalid Sourcefile");
}