vb.net drag and drop

Hello,
this function works perfectly fine to drag and drop text files into a listview..
I would like to know how can I make it compatible so that if you drag and drop a shortcut to a text file it loads the text file and not the shortcut..

    Private Sub lstMain_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lstMain.DragEnter
        If e.Data.GetDataPresent(System.Windows.Forms.DataFormats.FileDrop, False) Then
            e.Effect = DragDropEffects.Copy
        End If
    End Sub
    Private Sub lstMain_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lstMain.DragDrop
        If e.Data.GetDataPresent(System.Windows.Forms.DataFormats.FileDrop, False) Then
            Dim filenames() As String = DirectCast(e.Data.GetData(System.Windows.Forms.DataFormats.FileDrop), String())

            For Each file As String In filenames
                pathAccsImport = file
                Call LoadFileAccs(file, lstMain)
            Next
        End If
    End Sub

Open in new window

LVL 1
XK8ERAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
you need to resolve the .lnk files using the shelllink object:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb774004%28v=vs.85%29.aspx

 
Private Function ResolveShellLink(ByVal name As String) As String
    '--- Find the target for a short-cut
    If String.Compare(Path.GetExtension(name), ".lnk", True) <> 0 Then Return name

    Dim shl As New Shell32.Shell
    Dim dir As Shell32.Folder = shl.NameSpace(Path.GetDirectoryName(name))
    Dim itm As Shell32.FolderItem = dir.Items().Item(Path.GetFileName(name))
    Dim lnk As Shell32.ShellLinkObject = CType(itm.GetLink, Shell32.ShellLinkObject)
    Return lnk.Path
  End Function

Open in new window

0
XK8ERAuthor Commented:
yeah but where or how to I call function ResolveShellLink?
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
Call LoadFileAccs( ResolveShellLink(file), lstMain)
0
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

XK8ERAuthor Commented:
I get Shell32.Shell

is there another way to do this without shell32?
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
do you confirm that the variable (file) contains the full path?
I checked the function and it works just fine for me.
0
XK8ERAuthor Commented:
Error      2      Type 'Shell32.Shell' is not defined.
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you have to reference the Shell32.dll (from windows\system32 folder) to your project.
0
XK8ERAuthor Commented:
yeah no go with Shell32.Shell.. any other alternative ?
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
why "no go" with that one?
because that is, from what I know, the only way to do it.
you can do DLLImport of the Shell32.dll and do direct API calls with that, but in the end, it's the same technique.

to understand why it's the "only" way: the shortcut "feature" is part of the windows shell, so only windows shell can extract the information properly.

of course, you could open the file in binary mode, try to "guess" the format, and take the information.
but with next version of windows, the format of the file may change, and your app won't work any longer.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
XK8ERAuthor Commented:
perfect, I got it thanks so much
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.