如何将文件从路径复制到WPD或MTP设备

我正在使用 VB.NET 创建视频复制应用程序。我可以轻松地将所需的文件从路径复制到 USB,但是在使用手机等便携式设备时遇到同样的问题。

我正在使用 VB.NET 创建视频复制应用程序。我可以轻松地将所需的文件从路径复制到 USB,但是在使用手机等便携式设备时遇到同样的问题。

到目前为止,我能够使用此question中给出的代码和 DLL 找到并连接手机,但是在将文件复制到设备时遇到问题。

与此相关的子代码如下:

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
0

您的前一个主题有一个 greateanswer,其中包含您需要的所有信息。

在这里,您需要研究便携式设备documentation,编程指南-在设备内容上操作。在那里,您可以找到从 PC 到设备的复制文件的示例,并附带注释其工作原理。

您也可以从link下载整个示例项目。它包含内容传输示例。

简而言之:您应该创建一个流对象,其中包含要传输的文件数据,使用 CreateObjectWithPropertiesAndData 方法从内容对象,并将流数据复制到从内容接收的流。

复制完所有数据后,从 IPortableDeviceDataStream 调用 Commit,让驱动程序知道您已完成。

本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处

(252)
等待 redux操作完成调度
上一篇
Ubuntu20.04FocalFossaLinux上的 Viber安装问题
下一篇

相关推荐

发表评论

登录 后才能评论

评论列表(10条)