|
-
Aug 26th, 2012, 12:57 PM
#1
Thread Starter
Hyperactive Member
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
-
Aug 26th, 2012, 02:54 PM
#2
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|