Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将txt文件从Windows Mobile 6.5移动到Windows 7_C#_.net_Windows Mobile_Windows Mobile 6.5 - Fatal编程技术网

C# 如何将txt文件从Windows Mobile 6.5移动到Windows 7

C# 如何将txt文件从Windows Mobile 6.5移动到Windows 7,c#,.net,windows-mobile,windows-mobile-6.5,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");

我想将文件从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()

我还尝试使用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);**
有几件事可以尝试:

  • 您能否通过无线网络从笔记本电脑或其他PC连接到文件共享?我想确认这不是配置或身份验证问题

  • 假设#1起作用:尝试用PC的IP地址替换MYPERSONAL-PC

  • 假设#1有效,但#2无效:尝试p/Invoke建立到网络资源的本地连接(如映射网络驱动器)并复制到该网络资源


  • 我会将redir注册表项RegisterFSRoot设置为1,并查看设备上的\Network文件夹:。然后您可以使用文件复制功能复制到\Network\。其中,共享文件夹是从共享服务器映射的文件夹。如果未使用移动文件资源管理器连接到共享,则可以使用WNetAddConnection3添加连接和。使用C#时,您必须p/调用API:(用coredll.dll替换mpr.dll)

    此解决方案有什么不起作用?返回IOException,但我不知道为什么。是否有错误代码?我用错误更新问题。如果确定,函数wnetadConnection3将返回error\u success。如果不是,则必须使用GetLastWin32Error()来获取比异常更有意义的错误代码。接下来,我将在Try/catch中扩展块,并使用调试器对其进行设置。可能源文件丢失,或者您没有网络共享的写入权限。您是否尝试使用移动文件eplorer进行连接,然后将文件复制到共享?我尝试使用此解决方案(第二个答案):但返回我有关
    找不到DLL PInvoke'Mrp.DLL'
    的错误。如果您查看MSDN链接,底部显示在Windows mobile 6.5中,WNetAddConnection3是由coredll而不是mpr.dll导出的。是否验证WNetAddConnection3()调用成功?建立连接后,CopyTo()命令应指向连接的位置fi.CopyTo(@“logs”,true);