C# File.Copy source and destination folders requiere different user rights

女生的网名这么多〃 提交于 2019-12-10 20:18:48

问题


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?

来源:https://stackoverflow.com/questions/37873751/c-sharp-file-copy-source-and-destination-folders-requiere-different-user-rights

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!