2017-08-31 88 views
0

我的問題是將文件從一個系統複製到同一網絡上的另一個系統。我搜索了上述問題,我開始使用Mark Brackett's答案。如何解決WNetAddConnection2中的這個錯誤「ERROR_BAD_USERNAME」?

現在我打算將文件從我的系統複製到另一個系統,但我得到錯誤代碼53,67,2202。我成功解決了前兩個錯誤代碼。現在我被困在2202.請看下面的代碼。

NetworkCredential credentials = new NetworkCredential(@"\\192.168.0.110\", "krishna4"); 

private void btnClick_Click(object sender, EventArgs e) 
    { 
// NetwrokConnection(string networkName, NetworkCredential credentials) 
     using (new NetworkConnection("\\\\10.235.115.210\\d", credentials)) ; 
     System.IO.File.Copy("D:\\English\\parts.oxps", @"\\192.168.0.110\test\parts.oxps", true); 
    } 

請幫忙解決問題。提前致謝。

+0

,我的回答對您有用嗎? –

回答

1

我認爲你的連接憑證可能是錯誤的,它可能是無效的用戶名。

我建議參考以下鏈接:

ERROR_BAD_USERNAME

WNetUseConnection2 in C#

How to finish this implementation of creating a network share using WNetAddConnection2?

ERROR_BAD_USERNAME:指定的用戶名無效。

這裏是示例代碼;

using System; 
using System.IO; 
using System.Net;  

    class Program 
    { 
     static void Main(string[] args) 
     { 
      var networkPath = @"//server/share"; 
      var credentials = new NetworkCredential("username", "password"); 

      using (new NetworkConnection(networkPath, credentials)) 
      { 
      var fileList = Directory.GetFiles(networkPath); 
      } 

      foreach (var file in fileList) 
      { 
       Console.WriteLine("{0}", Path.GetFileName(file)); 
      }   
     } 
    } 
+0

@ Anjali,我希望這個答案對你有用! –

+0

是的,我做了一些修改。我將更新工作代碼.. – Anjali