This project is read-only.

Creating a folder on a WPD device

Dec 12, 2013 at 6:38 PM
Good day,

I am building an app that accesses a WPD device, specifically a GPS device.

I can connect to the device, enumerate the files and folders, read files, write files, pull properties of objects ... pretty much most of what I need to do except make folders.

I may be barking up the wrong tree, but I am trying to use CreateObjectWithPropertiesOnly method. Maybe SendCommand is the method to use?

My error is "Element not found. (Exception from HRESULT: 0x80070490)"}
System.Exception {System.Runtime.InteropServices.COMException}"

I am not sure if it is telling me it cannot find an element it is expecting or that one of the elements I have defined it cannot find.

Here is my code. My custom class CSBNewGPSFolder contains the new folder name, parentID, etc necessary for making the folder.

Any suggestions would be greatly appreciated.
    internal void CreateFolder(CSBNewGPSFolder NewFolderProperties)
    {
        // FolderObject, name: PropertiesV1 ///////////////////////////////////////////////////////////////////////////////
        IPortableDeviceContent content;
        this._device.Content(out content);
        PortableDeviceApiLib.IPortableDeviceValues DeviceValues =
                        (PortableDeviceApiLib.IPortableDeviceValues)new PortableDeviceTypesLib.PortableDeviceValuesClass();
        PortableDeviceApiLib.IPortableDeviceValues ResultValues =
                        (PortableDeviceApiLib.IPortableDeviceValues)new PortableDeviceTypesLib.PortableDeviceValuesClass();

        //// Object Format Properties Only ///////////////////////////////////////////// Object Format Properties Only ////
        //Guid WPD_OBJECT_FORMAT_PROPERTIES_ONLY = new Guid("30010000-ae6c-4804-98ba-c57b46965fe7");
        Guid WPD_CONTENT_TYPE_FOLDER = Guid.Empty;
        Guid WPD_OBJECT_FORMAT_ALL = new Guid("c1f62eb2-4bb3-479c-9cfa-05b5f3a57b22");
        Guid WPD_CONTENT_TYPE_ALL = new Guid("80e170d2-1055-4a3e-b952-82cc4f8a8689");

        // Parent ID (Parent folder) /////////////////////////////////////////////////////////////////////// Parent ID ////
        var WPD_OBJECT_PARENT_ID = new _tagpropertykey();
        WPD_OBJECT_PARENT_ID.fmtid = new Guid(0x7E9A7ABF, 0xE568, 0x4B34, 0xAA, 0x2F, 0x13, 0xBB, 0x12, 0xAB, 0x17, 0x7D);
        DeviceValues.SetStringValue(ref WPD_OBJECT_PARENT_ID, NewFolderProperties.WPD_OBJECT_PARENT_ID);
        this._device.SendCommand(0, DeviceValues, out ResultValues);

        // Object Name /////////////////////////////////////////////////////////////////////////////////// Object Name ////
        var WPD_OBJECT_NAME = new _tagpropertykey();
        WPD_OBJECT_NAME.fmtid = new Guid(0xEF6B490D, 0x5CD8, 0x437A, 0xAF, 0xFC, 0xDA, 0x8B, 0x60, 0xEE, 0x4A, 0x3C);
        WPD_OBJECT_NAME.pid = 4;
        DeviceValues.SetStringValue(ref WPD_OBJECT_NAME, NewFolderProperties.WPD_OBJECT_NAME);

        // Object Format Type ///////////////////////////////////////////////////////////////////// Object Format Type ////
        var WPD_OBJECT_FORMAT = new _tagpropertykey();
        WPD_OBJECT_FORMAT.fmtid = new Guid(0xEF6B490D, 0x5CD8, 0x437A, 0xAF, 0xFC, 0xDA, 0x8B, 0x60, 0xEE, 0x4A, 0x3C);
        WPD_OBJECT_FORMAT.pid = 6;
        DeviceValues.SetGuidValue(WPD_OBJECT_FORMAT, WPD_OBJECT_FORMAT_ALL);

        // Content Type All ///////////////////////////////////////////////////////////////////////////// Content Type ////
        var WPD_OBJECT_CONTENT_TYPE = new _tagpropertykey();
        WPD_OBJECT_CONTENT_TYPE.fmtid = new Guid(0xEF6B490D, 0x5CD8, 0x437A, 0xAF, 0xFC, 0xDA, 0x8B, 0x60, 0xEE, 0x4A, 0x3C);
        WPD_OBJECT_CONTENT_TYPE.pid = 7;
        DeviceValues.SetGuidValue(ref WPD_OBJECT_CONTENT_TYPE, WPD_CONTENT_TYPE_ALL);

        // Object is Hidden /////////////////////////////////////////////////////////////////// Object Hidden property ////
        if (NewFolderProperties.WPD_OBJECT_ISHIDDEN == true)
        {
            var WPD_OBJECT_ISHIDDEN = new _tagpropertykey();
            WPD_OBJECT_ISHIDDEN.fmtid = new Guid(0xEF6B490D, 0x5CD8, 0x437A, 0xAF, 0xFC, 0xDA, 0x8B, 0x60, 0xEE, 0x4A, 0x3C);
            WPD_OBJECT_ISHIDDEN.pid = 9;
            DeviceValues.SetBoolValue(ref WPD_OBJECT_ISHIDDEN, Convert.ToInt32(NewFolderProperties.WPD_OBJECT_ISHIDDEN));
        }

        // Object is System /////////////////////////////////////////////////////////////////// Object System Property ////
        if (NewFolderProperties.WPD_OBJECT_ISSYSTEM == true)
        {
            var WPD_OBJECT_ISSYSTEM = new _tagpropertykey();
            WPD_OBJECT_ISSYSTEM.fmtid = new Guid(0xEF6B490D, 0x5CD8, 0x437A, 0xAF, 0xFC, 0xDA, 0x8B, 0x60, 0xEE, 0x4A, 0x3C);
            WPD_OBJECT_ISSYSTEM.pid = 10;
            DeviceValues.SetBoolValue(ref WPD_OBJECT_ISSYSTEM, Convert.ToInt32(NewFolderProperties.WPD_OBJECT_ISSYSTEM));
        }

        // Object Key Words search //////////////////////////////////////////////////////////  Object Key Words search ////
        if (NewFolderProperties.WPD_OBJECT_KEYWORDS.Length > 0)
        {
            var WPD_OBJECT_KEYWORDS = new _tagpropertykey();
            WPD_OBJECT_KEYWORDS.fmtid = new Guid(0xEF6B490D, 0x5CD8, 0x437A, 0xAF, 0xFC, 0xDA, 0x8B, 0x60, 0xEE, 0x4A, 0x3C);
            WPD_OBJECT_KEYWORDS.pid = 15;
            DeviceValues.SetStringValue(ref WPD_OBJECT_KEYWORDS, NewFolderProperties.WPD_OBJECT_KEYWORDS);
        }

        // Object Cannot be Deleted ///////////////////////////////////////////////////////// Object Cannot be Deleted ////
        if (NewFolderProperties.WPD_OBJECT_CANNOT_DELETE == true)
        {
            var WPD_OBJECT_CAN_DELETE = new _tagpropertykey();
            WPD_OBJECT_CAN_DELETE.fmtid = new Guid(0xEF6B490D, 0x5CD8, 0x437A, 0xAF, 0xFC, 0xDA, 0x8B, 0x60, 0xEE, 0x4A, 0x3C);
            WPD_OBJECT_CAN_DELETE.pid = 26;
            DeviceValues.SetBoolValue(ref WPD_OBJECT_CAN_DELETE, Convert.ToInt32(NewFolderProperties.WPD_OBJECT_CANNOT_DELETE));
        }
        content.CreateObjectWithPropertiesOnly(DeviceValues, NewFolderProperties.DeviceID);
    }
Jun 20, 2014 at 11:06 AM
you refer to this link: cgeers.com/2012/04/17/wpd-transfer-content-to-a-device/#comment-10459
Aug 26, 2014 at 10:02 AM
The one line of Power-shell script below un-mounts a USB cable attached Windows Portable Device (WPD) from the Windows Operating System (XP thru W8/2012)

And just in case you have not yet started playing with Powershell, here is the equivalent VBScript (maybe be can port to C#):

Set objWMIService = GetObject ("winmgmts:\.\root\cimv2")
Set colItems = objWMIService.ExecQuery ("Select * from Win32ext_WPD Where strFriendlyName = 'SAMSUNG-SGH-I747'")
For Each objItem in colItems
Set objWMIWPDStatic = objWMIService.Get("Win32ext_WPD")
Set objInParam = objWMIWPDStatic.Methods_("EjectDevice").inParameters.SpawnInstance_()
objInParam.Properties_.Item("strObjectDeviceId") = objItem.strId
Set objOutParams = objWMIService.ExecMethod("Win32ext_WPD", "EjectDevice", objInParam)
Exit For
Next
Note change ‘SAMSUNG-SGH-I747′ to the phone/tablet name you see in Windows Explorer

About Win32ext_WPD

"Select * from Win32ext_WPD Where strFriendlyName = 'SAMSUNG-SGH-I747'"

Not well document googleing, not found more 2 references.

Maybe port to C# using:

var oScope = new ManagementScope(@"\" + MachineName + @"\root\cimv2"); Reference: http://squadratechnologies.wordpress.com/2013/07/24/windows-powershellvbscript-to-un-mount-a-smart-phone-or-tablet/