首页 > 解决方案 > 错误上传/下载文件到/从便携式设备使用

问题描述

我正在尝试无限循环地从 Android 三星平板电脑上传和下载文件。

示例代码是

while(true){
 var devices = MediaDevice.GetDevices();
using (var device = devices.First())
{

device.Connect();
device.UploadFile(@"C:/Inbox/file.pdf", @"\Tablet\Inbox\file.pdf");
device.Disconnect();

}

System.Threading.Thread.Sleep(5000);
//I manually delete the file from folder before the next iteration
}//while

问题如下:在第一次迭代中,文件被上传,当我从平板电脑中物理删除文件(收件箱文件夹为空)并尝试再次上传文件时,我得到一个文件存在的异常,但是,平板电脑的收件箱文件夹为空。

下载文件时问题相同。在第一次迭代中,文件被下载,但是当在平板电脑上物理创建另一个文件时,则: device.EnumerateFiles(@"\Tablet\Outbox\"); 返回空列表。

我怎么解决这个问题?

标签: c#tabletmediadevices

解决方案


推荐阅读