Question

I am trying to write an application that transfers data from a specific folder on a Windows portable device (here it is a Samsung Galaxy Note 2) to my PC.

I am able to successfully list all folders and files and I also can reach the specific folder I want via the WPD-API.

With the help of this page I wrote a class called "PortableDevice" that wraps every object on the device and creates a PortableDeviceObject out of it (this is a self made class and does not belong to the API) Here is the example of the wrapper method.

private static PortableDeviceObject WrapObject(IPortableDeviceProperties properties, string objectId)
        {
            PortableDeviceApiLib.IPortableDeviceKeyCollection keys;
            properties.GetSupportedProperties(objectId, out keys);

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

            // Get the name of the object
            string name;
            var property = new PortableDeviceApiLib._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 PortableDeviceApiLib._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, 0x5F, 0x85);
            var functionalType = new Guid(0x99ED0160, 0x17FF, 0x4C44, 0x9D, 0x98, 0x1D, 0x7A, 0x6F, 0x94, 0x19, 0x21);          

            if (contentType == folderType || contentType == functionalType)
            {
                return new PortableDeviceFolder(objectId, name);
            }

            return new PortableDeviceFile(objectId, name);
        }

When I access the name property, I would have thought that I always get the full name of the current object (a picture, or a music file etc). But only pictures are shown with the full name (for example test_picture.jpeg) but when I read a PDF in a folder, it only prints out the name of the PDF and not the .PDF extension. Thats problematic because I want to iterate over all files in a folder, want to get a datastream and fill this stream in a new file on my PC. It works so far, but all files (except pictures) are then created without the proper extension and therefore cannot be used or would have to be renamed manually.

So here is the question: How can I access the FULL PATH of every file in a folder on a WPD?

Was it helpful?

Solution

I found an answer in the comments of this site:

I just had to replace

return new PortableDeviceFile(objectId, name);

with

property.pid = 12;//WPD_OBJECT_ORIGINAL_FILE_NAME
values.GetStringValue(property, out name);
return new PortableDeviceFile(objectId, name);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top