|
-
Dec 15th, 2011, 01:01 AM
#1
Thread Starter
Lively Member
-
Dec 15th, 2011, 01:17 AM
#2
Re: filtering dragenter file in label?
First up, you are using DataFormats.FileDrop in the DragEnter handler and "FileDrop" in the DragDrop handler. There's no reason to be doing the same thing in two different ways. Pick one and stick to it. The obvious choice is to use the DataFormats enumeration.
Just as you can use GetDataPresent in both DragEnter and DragDrop, so too you can use GetData in both DragEnter and DragDrop. That means that you can get the data in DragEnter, use the IO.Path class to confirm that the name and/or the extension are valid and then allow the Copy effect or not based on that.
-
Dec 15th, 2011, 01:54 AM
#3
Thread Starter
Lively Member
Re: filtering dragenter file in label?
thank you jmc...
i found this code..
Code:
Dim Files() As String
Files = e.Data.GetData(DataFormats.FileDrop)
Dim sReader As New StreamReader(Files(0))
' get the filename from the file without the path
Dim file_name As String = Path.GetFileName(Files(0))
' check the extension of the file
If Path.GetExtension(Files(0)) = ".txt" Or _
Path.GetExtension(Files(0)) = ".blabla" Then
' do your thing
Else
' show warning
End if
last question how about getting filename?
edited: sorry for being newbie to vb.net i found out the answer of my question using Path.GetFileName
Last edited by Joke Sparrow; Dec 15th, 2011 at 02:02 AM.
-
Dec 15th, 2011, 03:16 AM
#4
Re: filtering dragenter file in label?
Note that you should never do anything twice when you can do it once and cache the result. There's no point calling GetExtension twice. Call it once, assign the result to a variable and then use that variable twice.
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
|