File.Copy() to file server with network Credential

2019-01-18 11:24发布

This question already has an answer here:

I am writing console application which will Copy file from my local disk to file server. This folder is protecting by username and password. File.Copy() method does not work. It gives permission error. I have looked to this code

I have tried it but it does not work. First it was written in VB but I have changed the code to C# but there are have some errors. I don't know what does this error mean. Maybe you can advise me other way coping file to protected File Server

with simple File.Copy(bla bla) it gives me "you have not permission"

when i converted VB code to C# it gived me error below: Attempted to read or write protected memory

I have found solution

You can Follow It

标签: c# file-io
1条回答
小情绪 Triste *
2楼-- · 2019-01-18 11:32

You could use the little impersonation class I wrote some years ago:

using ( new Impersonator( "myUsername", "myDomainname", "myPassword" ) )
{
   // code that executes under the new context.
   File.Copy( x, y );
}
查看更多
登录 后发表回答