如何将文本文件从Windows Mobile 6.5移动到Windows 7

时间:2014-02-19 10:46:12

标签: c# .net windows-mobile windows-mobile-6.5

我想将Windows Mobile中的文件移动到Windows中的特定文件夹。移动设备中的文件位于“我的文档”路径中。 设备连接到WiFi网络,Windows中共享的文件夹称为“文件夹”。

我该怎么做,我试过这个但是不起作用:

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 :(得分:1)

要尝试的一些事项:

  1. 您可以从无线网络上的笔记本电脑或其他PC连接到文件共享吗?我想验证它不是配置或身份验证问题。

  2. 假设#1有效:尝试用PC的IP地址替换MYPERSONAL-PC?

  3. 假设#1工作,但#2不工作:尝试P / Invoke WNetAddConnection3建立与网络资源的本地连接(如映射网络驱动器)并复制到该网络资源。

答案 1 :(得分: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#时,你必须p / invoke API:http://www.pinvoke.net/default.aspx/mpr.wnetaddconnection3(用coredll.dll替换mpr.dll)