資源簡介
鑒于大家的需要,上傳MTP文件拷貝傳輸代碼For C#,代碼僅提供參考,希望對大家有所幫助;
MTP設(shè)備文件并無盤符,是在MTP設(shè)備ID下,以樹形結(jié)構(gòu)存在的,操作時,我們其實操作的是文件的鏡像,文件操作全部使用的是文件ID.
MTP文件修改不存在修改功能,全部是本地修改然后覆蓋MTP設(shè)備上的文件;

代碼片段和文件信息
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#\PortableDeviceob
?????目錄??????????0??2014-01-08?15:17??Mtp?For?C#
-----------?---------??----------?-----??----
????????????????75912????????????????????7
- 上一篇:C#操作手持機識別RFID電子標簽
- 下一篇:會員積分管理系統(tǒng)C#版
評論
共有 條評論