• 大小: 21KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-01
  • 语言: C#
  • 标签: MTP  Copy  File  Ffor  C#  

资源简介

鉴于大家的需要,上传MTP文件拷贝传输代码For C#,代码仅提供参考,希望对大家有所帮助; MTP设备文件并无盘符,是在MTP设备ID下,以树形结构存在的,操作时,我们其实操作的是文件的镜像,文件操作全部使用的是文件ID. MTP文件修改不存在修改功能,全部是本地修改然后覆盖MTP设备上的文件;

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Text;
using PortableDeviceApiLib;

namespace WindowsFormsApplication13
{
    public class PortableDeviceFile : PortableDeviceobject
    {
        PortableDeviceClass ppDevice = new PortableDeviceClass();
        public PortableDeviceFile(string id string name)
            : base(id name)
        { }
        public PortableDeviceFolder GetContents()
        {
            var root = new PortableDeviceFolder(“DEVICE“ “DEVICE“);

            IPortableDeviceContent content;
            ppDevice.Content(out content);
            EnumerateContents(ref content root);
            return root;
        }
        private static void EnumerateContents(ref IPortableDeviceContent content PortableDeviceFolder parent)
        {
            // Get the properties of the object
            IPortableDeviceProperties properties;
            content.Properties(out properties);

            // Enumerate the items contained by the current object
            IEnumPortableDeviceobjectIDs objectIds;
            content.Enumobjects(0 parent.Id null out objectIds);

            uint fetched = 0;
            do
            {
                string objectId;

                objectIds.Next(1 out objectId ref fetched);
                if (fetched > 0)
                {
                    var currentobject = Wrapobject(properties objectId);

                    parent.Files.Add(currentobject);

                    if (currentobject is PortableDeviceFolder)
                    {
                        EnumerateContents(ref content (PortableDeviceFolder)currentobject);
                    }
                }
            } while (fetched > 0);
        }
        private static PortableDeviceobject Wrapobject(IPortableDeviceProperties properties string objectId)
        {
            IPortableDeviceKeyCollection keys;
            properties.GetSupportedProperties(objectId out keys);

            IPortableDeviceValues values;
            properties.GetValues(objectId keys out values);

            // Get the name of the object
            string name;
            var property = new _tagpropertykey();
            property.fmtid = new Guid(0xEF6B490D 0x5CD8 0x437A 0xAF 0xFC
                                        0xDA 0x8B 0x60 0xEE 0x4A 0x3C);
            property.pid = 4;
            values.GetStringValue(property out name);

            // Get the type of the object
            Guid contentType;
            property = new _tagpropertykey();
            property.fmtid = new Guid(0xEF6B490D 0x5CD8 0x437A 0xAF 0xFC
                                        0xDA 0x8B 0x60 0xEE 0x4A 0x3C);
            property.pid = 7;
            values.GetGuidValue(property out contentType);

            var folderType = new Guid(0x27E2E392 0xA111 0x48E0 0xAB 0x0C
                                        0xE1 0x77 0x05 0xA0 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      32768  2008-01-09 10:02  Mtp For C#\Interop.PortableDeviceApiLib.dll

     文件      28672  2008-01-09 12:15  Mtp For C#\Interop.PortableDeviceTypesLib.dll

     文件       9449  2014-01-08 15:15  Mtp For C#\MTP.CS

     文件       4168  2014-01-03 16:33  Mtp For C#\PortableDeviceFile.cs

     文件        433  2014-01-03 16:19  Mtp For C#\PortableDeviceFolder.cs

     文件        422  2014-01-03 16:18  Mtp For C#\PortableDeviceobject.cs

     目录          0  2014-01-08 15:17  Mtp For C#

----------- ---------  ---------- -----  ----

                75912                    7


评论

共有 条评论