题
我想写一个应用程序,这将复制MP3文件迪珊M240.闪迪没有一个驱动的信,并使用中期计划文件的传送。我偶然发现了通过样品连接的设备: http://blogs.msdn.com/dimeby8/archive/2006/09/27/774259.aspx
但是,一旦相连的,我想不出如何实际上复制文件的创建文件夹上的设备。
我非常惊讶的是,没有任何.净的包装这COM图书馆。
解决方案
其他提示
传送文件的通过中期计划c#:
下载这NuGet: PortableDevices
添加提到这4COM库:
- PortableDeviceClassExtension
- PortableDeviceConnectApi
- PortableDeviceTypes
- PortableDeviceApi
采取dll下
obj\Debug
并把它们放进bin\Debug
:- Interop.PortableDeviceClassExtension.dll
- Interop.PortableDeviceConnectApiLib.dll
- Interop.PortableDeviceTypesLib.dll
- Interop.PortableDeviceApiLib.dll
现在你可以用下面的功能清单的所有设备,尽管 FriendlyName
似乎没有工作(就返回的一个空string):
private IDictionary<string, string> GetDeviceIds()
{
var deviceIds = new Dictionary<string, string>();
var devices = new PortableDeviceCollection();
devices.Refresh();
foreach (var device in devices)
{
device.Connect();
deviceIds.Add(device.FriendlyName, device.DeviceId);
Console.WriteLine(@"DeviceId: {0}, FriendlyName: {1}", device.DeviceId, device.FriendlyName);
device.Disconnect();
}
return deviceIds;
}
下一步是获取内容的设备,这样做是像这样:
var contents = device.GetContents();
不隶属于 StackOverflow