I have an application that copies files that could be located anywhere on the local hard drive to a directory on a network share. The network directory is only accessible for a special domain account. I generally solved the problem by using an Impersonator-Class in this way:
using(new MyImpersonator()
{
File.Copy(source, destination);
}
But this causes problems when I want to copy a file from a special directory, for example the Windwos-Dektop. Then I get an UnauthorizedAccessException because the domain account that has rights to write on the network share doesn't have the rights to read from the local Desktop. Giving the special domain account the right to read from every folder on the local computer during installation is not an option because of restrictions from my costumer.
A workaround for me is to create a temp directory in C:\ProgramData\MyApp that could be accessed by both, the local and the network user and copy the files at first to this temp directory and then with the special domain account to the network share. But this is not very performant.
Does anyone have a smarter solution for this problem?