在drag&amp ;;上检索FTP文件的完整路径下降?

时间:2015-06-22 19:51:45

标签: vb.net ftp

从Windows资源管理器上浏览的Ftp文件夹中拖动文件时,我可以使用下一代码读取文件名。 但有没有办法检索完整的Ftp路径?

    Private Sub DataGridView1_DragDrop(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles DataGridView1.DragDrop
    Dim filename As String = ""
    If e.Data.GetDataPresent("UniformResourceLocator") Then
        Dim ioStream As System.IO.Stream = DirectCast(e.Data.GetData("FileGroupDescriptor"), System.IO.Stream)
        Dim contents As Byte() = New [Byte](511) {}
        ioStream.Read(contents, 0, 512)
        ioStream.Close()
        Dim sb As New System.Text.StringBuilder()
        Dim i As Integer = 76
        While contents(i) <> 0
            sb.Append(CChar(ChrW(contents(i))))
            i += 1
        End While

        filename = sb.ToString()
    End If

End Sub

1 个答案:

答案 0 :(得分:2)

如果删除的数据包含UniformResourceLocator格式,您可以从中获取整个URL,例如:

   Private Sub Form1_DragDrop(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop

      If e.Data.GetDataPresent("UniformResourceLocator") Then
         Dim URL As String = New IO.StreamReader(CType(e.Data.GetData("UniformResourceLocator"), IO.MemoryStream)).ReadToEnd
      End If

   End Sub

首先检查是否存在UniformResourceLocator格式,如果存在,则从e获取数据(拖放参数),将其转换为MemoryStream,并将其传递给新的StreamReader(以便于阅读),然后执行.ReadToEnd()来获取整个字符串。