【发布时间】:2016-12-28 16:24:27
【问题描述】:
我想将文件从本地驱动器复制到共享网络路径。
我尝试了以下方法:
string remoteUserName =
WebConfigurationManager.AppSettings["remoteUsername"].ToString();
string remotePassword =
WebConfigurationManager.AppSettings["remotePassword"].ToString();
string remoteDomain =
WebConfigurationManager.AppSettings["remoteDomain"].ToString();
string remoteFilePath =
WebConfigurationManager.AppSettings["remoteFilePath"].ToString();
using (var impersonation = new
ImpersonatedUser(remoteUserName, remoteDomain, remotePassword))
{
CreateErrorLog("Logged in successfully - User and password are correct.",
"Action" + " - " + "controllerName");
string filePath = remoteFilePath;
string fileName = "txt.txt";
StreamWriter SW1;
FileIOPermission myPerm = new
FileIOPermission(FileIOPermissionAccess.AllAccess, filePath + fileName);
myPerm.Assert();
SW1 = System.IO.File.CreateText(filePath + fileName);
}
【问题讨论】:
-
这在什么方面不起作用?您是否收到错误消息?如果有,那是什么?
-
您可以简单地将 Process.Start 用作其他用户,请参阅 stackoverflow.com/questions/4624113/… 或者,将您的模拟更改为使用 WindowsIdentity.Impersonatehttp://stackoverflow.com/questions/125341/how-do-you -do-impersonation-in-net 并使用以下命令检查您的模拟实体msdn.microsoft.com/en-us/library/aa347790(v=vs.110).aspx
标签: c#