【发布时间】:2015-01-19 16:00:16
【问题描述】:
我需要使用 c# 动态上传文件。我可以用 asp.net 做到这一点,但 O 不能用桌面应用程序做到这一点。
我正在通过打开文件对话框上传文件。这是我的代码
string path = "";
OpenFileDialog fDialog = new OpenFileDialog();
fDialog.Title = "Attach PMI document";
fDialog.Filter = "PDF docs|*.pdf|JPG Files|*.jpg|JPEG Files|*.jpeg";
fDialog.InitialDirectory = @"Desktop";
if (fDialog.ShowDialog() == DialogResult.OK)
{
fileName = System.IO.Path.GetFileName(fDialog.FileName);
path = Path.GetDirectoryName(fDialog.FileName);
textBox1.Text = path + "\\" + fileName;
}
打开文件对话框没有问题。
当我尝试将此代码保存到我的计算机时,它是成功的
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
WindowsIdentity idnt = new WindowsIdentity(username, password);
WindowsImpersonationContext context = idnt.Impersonate();
File.Copy(@"\\192.100.0.2\temp", @"D:\WorkDir\TempDir\test.txt", true);
context.Undo();
但是当我尝试将文件复制到网络时,它会给出“提供用户名的错误帐户名格式不正确”
我怎样才能复制它 谢谢。
【问题讨论】:
-
"F\"缺少一个冒号?您有到 192.168.2.92 的路线吗?如果你开始 -> 运行 -> \\192.168.2.92\Ender\Files\ 会发生什么 -
好消息@AlexK。我完全错过了!
-
@AlexK。 F 是我的本地磁盘。而 192.168.2.92 是我的服务器计算机的 IP。我的电脑已经使用用户名 asd\ender 和密码 ender 登录到服务器。
-
请记住现在更改您的凭据。那永远不应该公开。有些小伙子很方便,你知道......
-
感谢更新,您是否尝试使用有效的 UPN 用户名指定用户名?请参阅我的更新答案。
标签: c# file-upload server