2014-02-19 38 views
0

我想將文件從Windows Mobile移動到Windows中的特定文件夾。移動設備中的文件位於「我的文檔」路徑中。 設備連接到WiFi網絡,並且在Windows中共享的文件夾被稱爲「文件夾」。如何將txt文件從Windows Mobile 6.5移動到Windows7

我怎麼能這樣做,我試過,但不起作用:

var f= System.Enviroment.GetFolderPath(System.Enviroment.SpecialFolder.Personal); 
FileInfo fi = new FileInfo(f.ToString() + @"\file.txt"); 
fi.CopyTo(@"\\MYPERSONAL-PC\folder",true); 

的錯誤是:

in System.IO.__Error.WinIOError(Int32 errorCode, String str) 
in System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite) 
in System.IO.FileInfo.CopyTo(String destFileName, Boolean overwrite) 
in Project.MainForm.SaveButton_Click(Object sender, EventArgs e) 
in System.Windows.Forms.Control.OnClick(EventArgs e) 
in System.Windows.Forms.Button.OnClick(EventArgs e) 
in System.Windows.Forms.ButtonBase.WnProc(WM wm, Int32 wParam, Int32 lParam) 
in System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam) 
in Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain) 
in System.Windows.Forms.Application.Run(Form fm) 
in Project.Program.Main() 

enter image description here

我還試圖用WNetAddConnection3,但仍與網絡資源的連接是一樣的,但總是返回相同的代碼在這裏:

[StructLayout(LayoutKind.Sequential)] 
    internal struct NetResource 
    { 
     public uint dwScope; 
     public uint dwType; 
     public uint dwDisplayType; 
     public uint dwUsage; 
     [MarshalAs(UnmanagedType.LPWStr, SizeConst = 64)] 
     public string lpLocalName; 
     [MarshalAs(UnmanagedType.LPWStr, SizeConst = 64)] 
     public string lpRemoteName; 
     [MarshalAs(UnmanagedType.LPWStr, SizeConst = 64)] 
     public string lpComment; 
     [MarshalAs(UnmanagedType.LPWStr, SizeConst = 64)] 
     public string lpProvider; 
    } 


[DllImport("coredll.dll")] 
private static extern int WNetAddConnection3(IntPtr hWndOwner, 
ref NetResource lpNetResource, string lpPassword, string lpUserName, int dwFlags); 

[DllImport("coredll.dll")] 
static extern int WNetCancelConnection2(string lpName, Int32 dwFlags, bool bForce); 

var f= System.Enviroment.GetFolderPath(System.Enviroment.SpecialFolder.Personal); 

NetResource logsResource = new NetResource(); 
logsResource.lpLocalName = "logs"; 
logsResource.lpRemoteName = @"\\MYPERSONAL-PC\folder"; 
logsResource.dwType = 0x1; 
logsResource.dwScope = 0; 
logsResource.dwUsage = 0; 
logsResource.dwDisplayType = 0; 

//try to connect the network resource 
WNetAddConnection3(new IntPtr(0), ref logsResource, @"pass", @"dom\user", 0); 
FileInfo fi = new FileInfo(f.ToString() + @"\file.txt"); 
**fi.CopyTo(@"\\MYPERSONAL-PC\folder", true);** 
+2

什麼不適用於此解決方案? –

+0

返回我IOException,但我不知道爲什麼。 – puti26

+2

這是什麼意思? –

回答

1

有幾件事情嘗試:

  1. 是否可以從一臺筆記本電腦或其他個人電腦連接到文件共享的無線網絡上?我想驗證它不是配置或身份驗證問題。

  2. 假設#1有效:嘗試用PC的IP地址替換MYPERSONAL-PC?

  3. 假設#1有效,但#2沒有:嘗試P /調用WNetAddConnection3以建立到網絡資源的本地連接(如映射網絡驅動器)並將其複製到該網絡資源。

+0

我正在使用此解決方案(第二個答案):[link](http:// stackoverflow。com/questions/659013/access-a-shared-file-unc-from-a-remote-non-trusted-domain-with-credentials)但返回錯誤*'無法找到DLL PInvoke'Mrp.dll' '* – puti26

+1

如果你看一下MSDN鏈接,在底部,它表示在Windows Mobile 6.5中,WNetAddConnection3是由coredll而不是mpr.dll導出的。 – PaulH

+0

您是否驗證過WNetAddConnection3()調用成功?在你建立連接後,你的CopyTo()命令應該指向連接的位置fi.CopyTo(@「logs」,true); – PaulH

1

我會將redir註冊表項RegisterFSRoot設置爲1並查看設備上的\ Network文件夾:http://msdn.microsoft.com/en-us/library/aa922326.aspx。然後您可以使用文件複製功能複製到\ Network \。共享文件夾是您從共享服務器映射的文件夾。如果您沒有使用移動文件資源管理器連接到共享,則可以使用WNetAddConnection3添加連接http://msdn.microsoft.com/en-us/library/aa916067.aspxhttp://msdn.microsoft.com/en-us/library/aa917445.aspx。當使用C#時,必須調用API:http://www.pinvoke.net/default.aspx/mpr.wnetaddconnection3(用coredll.dll替換mpr.dll)

相關問題