How to copy files from path to WPD or MTP device

1.5k Views Asked by At

I'm using VB.NET to create a video copying application. I can easily copy the files I need from path to USB, but I am having trouble doing the same with portable devices such as phones.

So far I was able to find and connect the phone using the code and DLL given in this question, but I am having trouble copying files to the device.

My code of the sub related to this is as follows:

Imports System.IO
Imports PortableDevices

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        MsgBox("Please make sure that your device is connected! Press ok to continue", MsgBoxStyle.OkOnly)

        For Each item In listID.Items
            table = Universal.convertType(item.ToString.Remove(6), 1)
            colInitials = Universal.getStringUntilChar(table, "_")
            'Code to get the file path stored in sql and store it as filePath
            Dim filePath As New DirectoryInfo(SQL.getRecordedValue(table, 
            colInitials & "Location", colInitials & "ID", item.ToString.Remove(0, 6)))
            Dim folderName As String = filePath.Name
            ' build collection for the devices
            Dim pds As New PortableDeviceCollection
            ' get dev list
            pds.Refresh()
            For Each device In pds
                ' connect before doing stuff
                device.Connect()

                ' find out what treasures are stored here
                Dim root = device.GetContents()
                ' the root is the startingm root folder

                'Dont know what to do here

                ' disconnect from this device
                device.Disconnect()

            Next
            pds.First.Disconnect()

        Next
    End Sub
1

There are 1 best solutions below

0
On

You have a greate answer to your previous topic, that contains all information you needed.

Here you need to study portable devices documentation, Programming Guide -> Operating on Device Content. There you can find sample of copy file from PC to device, with comments how it works.

You can also download the whole sample project from link. It contains sample of content transfering.

In short words: you should create a stream object, that contains file data you want to transfer, use CreateObjectWithPropertiesAndData method from content object, and copy your stream data to stream received from content.

After all the data is copied, call Commit from IPortableDeviceDataStream to let driver know you are finished.