File.Copy()到文件与网络凭证服务器 [英] File.Copy() to file server with network Credential

查看:201
本文介绍了File.Copy()到文件与网络凭证服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写控制台应用程序将从我的本地磁盘将文件复制到文件服务器。此文件夹的用户名和密码保护。 File.Copy()方法不工作。它提供了权限错误。 <一href=\"http://stackoverflow.com/questions/766033/copy-file-to-remote-computer-using-remote-admin-credentials/766086#766086\">i看过这个code

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 works. it gives permission error. i have looked to this code

我已经尝试过了。但它不工作。首先它是用VB写的,但我已经改变了code到C#但是有一些错误。但不知道什么是错误。也许你可以告诉我另一种方式来将文件复制到受保护的文件服务器

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 has some error. but don't know what is a error. Maybe you can advise me another way to copy file to protected File Server

简单File.Copy(BLA BLA)它给了我你没有权限

当我转换VB code到C#这红粉我下面的错误:试图读取或写入受保护的内存

我已经找到解决方案。

<一个href=\"http://stackoverflow.com/questions/295538/how-to-provide-user-name-and-password-when-connecting-to-a-network-share\">You可以按照它

推荐答案

您可以使用模仿小类我几年前写的:

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 );
}

这篇关于File.Copy()到文件与网络凭证服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆