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
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:
Private Sub TextBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragDrop
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
Dim Files As String() = DirectCast(e.Data.GetData(DataFormats.FileDrop), String())
TextBox2.Text = System.IO.Path.GetFileName(Files(0))
End If
End Sub