为什么我在尝试从网络驱动器复制文件时遇到访问被拒绝的问题? [英] Why I am getting access denied issue while trying to copy file from a network drive?

查看:524
本文介绍了为什么我在尝试从网络驱动器复制文件时遇到访问被拒绝的问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将具有完全权限的映射网络驱动器文件夹中的文件复制到我本地驱动器中的文件夹。

我可以打开文件,更改所有内容。但是在复制访问被拒绝的问题上显示

以下是我的代码。

tring username = @ rahul @ chn.nestgroup.net;

< br $>


string password =abcd *;









AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);



WindowsIdentity idnt =新的WindowsIdentity(用户名,密码) ;



WindowsImpersonationContext context = idnt.Impersonate();

string source = @Z:\ helo.txt;

string destPath = @D:\ Test \ abcd.txt;

File.Copy(source,destPath);



我尝试过:



tring username = @ rahul @ chn.nestgroup.net;





string password =abcd *;









AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);



WindowsIdentity idnt =新的WindowsIdentity(用户名,密码);



WindowsImpersonationContext context = idnt.Impersonate();

string source = @Z:\ helo.txt;

string destPath = @D:\ Test \abcd.txt;

File.Copy(source,destPath);

I am copying files from a mapped network drive folder with full privilege to a folder in the local drive of mine.
I am able to open the file,change and all. But on copying access denied issue shown
Below is my code.
tring username = @rahul@chn.nestgroup.net";


string password = "abcd*";




AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);

WindowsIdentity idnt = new WindowsIdentity(username, password);

WindowsImpersonationContext context = idnt.Impersonate();
string source= @"Z:\helo.txt";
string destPath = @"D:\Test\abcd.txt";
File.Copy(source, destPath);

What I have tried:

tring username = @rahul@chn.nestgroup.net";


string password = "abcd*";




AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);

WindowsIdentity idnt = new WindowsIdentity(username, password);

WindowsImpersonationContext context = idnt.Impersonate();
string source= @"Z:\helo.txt";
string destPath = @"D:\Test\abcd.txt";
File.Copy(source, destPath);

推荐答案

可能的原因可能是目标文件已存在。在这种情况下,您的 File.Copy 版本将失败。要覆盖现有文件,请使用 File.Copy方法(字符串,字符串,布尔值) )(System.IO) [ ^ ],覆盖参数设置为true。请注意,当目标文件存在且读取时,这可能也会失败。然后你必须在复制之前删除只读属性。
A possible reason may be that the destination file exists already. Your File.Copy version fails in that case. To overwrite existing files use the File.Copy Method (String, String, Boolean) (System.IO)[^] with the overwrite parameter set to true. Note that that may fail too when the destination file exists and is read only. Then you have to remove the read only attribute before copying.


这篇关于为什么我在尝试从网络驱动器复制文件时遇到访问被拒绝的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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