This is the C# equivalent of an earlier C++ post on connecting to a WPD device. We'll concentrate on the implementation here - you may refer back to that earlier post for further explanation.
// Create our client information collection
PortableDeviceApiLib.IPortableDeviceValues pValues =
// We have to provide at the least our name, version, revision
ref PortableDevicePKeys.WPD_CLIENT_NAME, "Sample Client");
ref PortableDevicePKeys.WPD_CLIENT_MAJOR_VERSION, 1);
ref PortableDevicePKeys.WPD_CLIENT_MINOR_VERSION, 0);
ref PortableDevicePKeys.WPD_CLIENT_REVISION, 2);
// Create a new IPortableDevice instance
PortableDeviceApiLib.PortableDeviceClass pPortableDevice =
// We are now ready to open a connection to the device
// We'll assume deviceID contains a valid WPD device path and connect to it
As you can see, it's pretty straight-forward to open a connection to a WPD device. We will set up our client information in a PortableDeviceValues collection and then send in the collection to the Open API call. If the device ID was valid, then a device connection will be opened and we can begin to use pPortableDevice to communicate with the device.