Question

I would like to move a file from Windows Mobile to a specific folder in Windows. The file in the mobile device is into the My Documents path. The device is connected to the WiFi network, and the folder shared in windows is called "folder".

How could I do, I tried this but doesn't work:

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

the error is :

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

I also tried to use WNetAddConnection3, but still the same the connection to the network resource is ok, but return me always the same the code is here:

[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);**
Was it helpful?

Solution

A few things to try:

  1. Can you connect to the file share from a laptop or other PC on the wireless network? I want to verify it's not a configuration or authentication problem.

  2. Assuming #1 works: try replacing MYPERSONAL-PC with the IP address of the PC?

  3. Assuming #1 works, but #2 does not: try to P/Invoke WNetAddConnection3 to make a local connection to a network resource (like mapping a network drive) and copy to that.

OTHER TIPS

I would set the redir registry entry RegisterFSRoot to 1 and see the \Network folder on the device: http://msdn.microsoft.com/en-us/library/aa922326.aspx. Then you can use the file copy function to copy to \Network\. Where shared folder is the one you mapped from the sharing server. If you did not Connect to the share using mobile File Explorer, you can use WNetAddConnection3 to add the connection http://msdn.microsoft.com/en-us/library/aa916067.aspx and http://msdn.microsoft.com/en-us/library/aa917445.aspx. When usig C# you have to p/invoke the APIs: http://www.pinvoke.net/default.aspx/mpr.wnetaddconnection3 (replace mpr.dll with coredll.dll)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top