如何在C#中将文件从手机复制到PC时处理异常?

时间:2016-08-08 14:36:54

标签: c# android file-copying mtp

我正在尝试将连接的Android设备中的文件复制到我的电脑上。

    public void CopyFiles(Folder srcFolder, Folder FolderImages, Folder FolderDatabase)
    {
        ImageFileCounter = 0;
        SqlLiteCounter = 0;
        foreach (FolderItem currFolderItem in srcFolder.Items())
        {
            if (currFolderItem.IsFolder) continue;

            if (currFolderItem.Type.Equals("JPG File") || currFolderItem.Type.Equals("PNG File"))
            {
                FolderImages.CopyHere(currFolderItem, 4 | 16);
                ImageFileCounter++;
            }
            else if (currFolderItem.Type.Equals("Data Base File"))
            {
                FolderDatabase.MoveHere(currFolderItem, 4 | 16);
                SqlLiteCounter++;
            }
        }
    }

我想在复制文件时断开设备连接时处理复制错误。谁能知道我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

我找到了解决方案。无法获取有关Folder.CopyHere()或Folder.MoveHere()最终结果的信息。我在这里找到了答案https://msdn.microsoft.com/pl-pl/library/windows/desktop/bb787866(v=vs.85).aspx。抱歉愚蠢的问题。