/** * Copy test file to device. */ public static String copyToDevice(PortableDevice device) { String error = ""; try { // Try to find the data folder on the phone. String phoneDir = @"Phone\Android\data"; PortableDeviceFolder root = device.Root; PortableDeviceFolder result = root.FindDir(phoneDir); if (null == result) { // Perhaps it was a tablet instead of a phone? result = device.Root.FindDir(@"Tablet\Android\data"); phoneDir = @"Tablet\Android\data"; } // Did we find a the desired folder on the device? if (null == result) { error = phoneDir + " not found!"; } else { // Create remote test folder. result = result.CreateDir(device, "test"); string pcDir = @"C:\Test\"; if (COPY_FOLDER) { // copy a whole folder. public void CopyFolderToPhone (PortableDevice device, String folderPath, String destPhonePath) result.CopyFolderToPhone(device, pcDir, phoneDir); } else { // Or Copy a single file. device.TransferContentToDevice(result, pcDir + "foo.txt"); } } } catch (Exception ex) { error = ex.Message; } return(error); }
/** * CopyFolderToPhone */ public void CopyFolderToPhone(PortableDevice device, String pcPath, String phonePath) { String errors = ""; // Get all the files in the dir. string[] files = Directory.GetFiles(pcPath, "*.*", SearchOption.TopDirectoryOnly); foreach (var fn in files) { try { device.TransferContentToDevice(this, fn); } catch (Exception ex) { errors += @"\n\n" + ex.Message; } } // Got errors? if (!String.IsNullOrEmpty(errors)) { throw new Exception(errors); } }