Results 1 to 2 of 2

Thread: drag & drop get filename only, NOT path

  1. #1
    Hyperactive Member
    Join Date
    Jul 11
    Posts
    419

    drag & drop get filename only, NOT path

    Hi, i have this code where when you drag&drop a file to the textbox it gets the path of the file.

    This works great, however i want to get just the filename not the full path.

    How would i do this ?

    Code:
    Private Sub TextBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragDrop
    
            Dim Files As String() = CType(e.Data.GetData(DataFormats.FileDrop), String())
    
            TextBox2.Text = Files(0)
    
        End Sub
    Thanks for any help

  2. #2
    Hyperactive Member
    Join Date
    Jul 11
    Location
    UK
    Posts
    436

    Re: drag & drop get filename only, NOT path

    You do realise you are handling the event for TextBox1 and updating TextBox2?

    See the IO.Path Class

    vb.net Code:
    1. Private Sub TextBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragDrop
    2.  
    3.     If e.Data.GetDataPresent(DataFormats.FileDrop) Then
    4.  
    5.         Dim Files As String() = DirectCast(e.Data.GetData(DataFormats.FileDrop), String())
    6.         TextBox2.Text = System.IO.Path.GetFileName(Files(0))
    7.  
    8.     End If
    9.  
    10. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •