Reputation: 734
I am going to create an c# windows application for transfering image file from an android phone to my Wondows PC - when I connect phone with my PC(using data cable). When I given the path "Computer/Nuxes5/..." in C# for accessing files from mobile, (Got from the windows Explorer address bar). Then getting incorrect path. Following is the code I have given for accessing files.
Directory.GetFiles(@"Computer/Nuxes5/...");
Can any one please suggest me, how to access the mobile files using C#.
Upvotes: 5
Views: 3466
Reputation: 41
You need to use MTP file transfer. Since you are using Windows, the best thing to do is to use COM with the Windows PortableDeviceApiLib library. This is not an easy task. The WPD API link in one of the comments above is a good reference.
You should also install Microsoft MTP Simulator 3.0 and look at the sample code that comes with it.
In MTP, every file or folder stored on the device is an object with a handle. To retrieve a file or a folder, you have to retrieve the object handle, then check to see if it is a file or a folder by checking its objectFormatCode property. Folders have the object format code set to 0x3001. You can get the entire list from the MTP Spec.
Once you have the WPD/PTP wrapper set up, you can start sending MTP commands to the device. For getting files from the device, the procedure is the following.
Also remember that you cannot download all the contents at the same time. You have to call getObject() for each file handle you need to download.
Upvotes: 1