例外:找不到网络名称。 [英] Exception: the network name cannot be found.

查看:179
本文介绍了例外:找不到网络名称。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在使用.net 4.5 Framework,WPF和c#上的桌面应用程序。我有Windows 8机器。我试图在网络路径上传我的本地文件,为此我使用file.copy()但是当我尝试执行它时显示无法找到网络名称。例外。



代码如下:



Hi,

I am working on desktop application on .net 4.5 Framework, WPF and c#. I have windows 8 machine. I am trying to upload my local file in network path, for this i am using file.copy() but when I am trying to executing it shows "The network name cannot be found." Exception.

Code is as follows:

using (new Impersonator("username", "domain", "password"))
{
File.Copy(System.IO.Path.GetFullPath(strNetworkFileName),System.IO.Path.GetFullPath(networkPath), true);
 }





我的尝试:



我尝试了Impersonator接口,但即使它不起作用。



What I have tried:

I tried Impersonator interface but even that it's not working.

推荐答案

你正在使用UNC路径来处理这两个文件规范。一个合适的UNC路径是\\server\ shareName \ folder \ file.ext。



localpath 不应该是UNC路径,因为我怀疑您路径中的第一个文件夹是有效的共享。工作站通常没有共享设置,除了默认的管理类型。



您的本地路径应该是完全限定的(以驱动器号开头)路径本地文件。



目标服务器必须公开您可以上传的共享。您不能只指定机器名称和要放入的文件夹。
You're using UNC paths for both file specifications. A proper UNC path is "\\server\shareName\folder\file.ext".

The "localpath" should not be a UNC path as I doubt the first "folder" in your path is a valid Share. Workstations don't normally have Shares setup, except for the default administrative variety.

Your local path should be a fully qualified (starts with a drive letter) path to the local file.

The destination server MUST expose a Share that you can upload to. You can NOT just specify a machine name and a folder to put it in.


这篇关于例外:找不到网络名称。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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