Using the Windows Portable Devices (WDP) API for fun and... fun...

Description

Today's Mobile Monday post is going to be different than most... Instead of Windows Phone 7, etc, we're going to focus on a series of posts that covers an API that many may not know about, but once you do, might get you thinking about the cool stuff you can do with it (I know I am...)

What is this API? The Windows Portable Devices (WDP) API. This is a COM API that is not the most .Net friendly, yet Christophe Geer has a working series of posts that walks you through using it in .Net, from enumeration the content, to grabbing content off, deleting stuff and in the latest post, transfer content from your computer to the device.

What kinds of devices? He shows off examples with cameras and Kindles. So imaging writing some kind of cool utility that explorers, lists, transfers stuff to and from your Kindle. Or building that kind of thing into one of your own app's...

Let's focus on the latest post;

WPD: Transfer Content To A Device

Mayhap came here sooner than I thought. The previous article on the WPD API dealt with deleting resources. Too destructive perhaps, let’s create some resources this time.

My Kindle’s is hooked up to my PC. Let’s see if I can transfer a book to it.

Table Of Contents

TransferContentToDevice Method

Get the source code of the fourth article, #69: WPD: Deleting Resources, from the download page. Unzip it and open it up in Visual Studio.

image

image

In the Solution Explorer select the Program.cs file and open it. Clear the Main(…) method and add the following code to it.

var devices = new PortableDeviceCollection();
devices.Refresh();
var kindle = devices.First();
kindle.Connect();

kindle.TransferContentToDevice(
@"d:\temp\Kindle_Users_Guide.azw",
@"g:\documents");

kindle.Disconnect();

First we establish a connection to the Kindle, copy the book to it and finally disconnect from it

The magic happens in the TransferContentToDevice(…) method, which takes two parameters:

  • fileName: Full path of the file which you want to copy to the device
  • parentObjectId: The ID of the parent folder into which you want to copy the file

Modify the values of these parameters to suit your situation.

Required Properties

Before we can start to implement the TransferContentToDevice(…) method we first need to add another private method to the PortableDevice class type.

....

The post continues into much more depth and details and provides from good geek reading. The other posts in this series are the same, providing simple examples up front and then going into a very nice level of details.

If you've always wanted to build a utility for that portable device, camera, Zune (yes, Zune, I was able to at least get a very raw listing of my Zune HD's content) or Kindle, this is a series of posts you should check out.

Tag:

Coding4Fun

The Discussion

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to send us feedback you can Contact Us.