public void CopyFolderToPC(PortableDevice device, String pcPath) { String errors = ""; // Go thru all the files on the Phone. foreach (var file in Files) { try { if (file is PortableDeviceFile) { device.TransferContentFromDevice((PortableDeviceFile)file, pcPath, file.Name); } else { errors += @"Could not find file:" + file.Name; } } catch (Exception ex) { errors += " " + ex.Message + " "; } } // Got errors? if (!String.IsNullOrEmpty(errors)) { throw new Exception(errors); } }
/** * Copy test file to device. */ public static String copyFromDevice(PortableDevice device) { String error = ""; try { PortableDeviceFolder root = device.Root; PortableDeviceObject result = root.FindDir(@"Phone\Android\data\test"); if (null == result) { // Perhaps it was a tablet instead of a phone? result = root.FindDir(@"Tablet\Android\data\test"); } // Did we find a the desired folder on the device? if (null == result) { error = @"Dir Android\data not found!"; } else if (result is PortableDeviceFolder) { if (COPY_FOLDER) { // Copy a whole folder ((PortableDeviceFolder)result).CopyFolderToPC(device, @"C:\Test\CopiedBackfromPhone"); } else { // Or Copy a file PortableDeviceFile file = ((PortableDeviceFolder)result).FindFile("foo.txt"); device.TransferContentFromDevice(file, @"C:\Test\CopiedBackfromPhone", "Copyfoo.txt"); } } } catch (Exception ex) { error = ex.Message; } return(error); }