I have a commondialog on my form, 1 textbox, 1 command button.

I want to show the path of a link(link file) on the textbox using the commondialog? how should I?

When I write the following code, I get the path of the actual file and not the path of the .lnk file

CommonDialog1.Filter = "Link Files (.lnk)|*.lnk"
CommonDialog1.ShowOpen
text1.text= CommonDialog1.FileName

Any suggestions?

Thanx :)

Here is a function you can use, just stick it in a module:

Public Function GetShortcutPath(ByVal FileName As String)
    ' /* Declare Variable To Hold Shell Object */
    Dim WSH As Object
    ' /* Actually Set The Variable To A New Instance Of WScript Shell */
    Set WSH = CreateObject("WScript.Shell")
    
    ' /* Declare Variable To Point To The Shortcut */
    Dim sc As Object
    ' /* Set The Variable To The CreateShortcut Method of WSH */
    Set sc = WSH.CreateShortcut(FileName)
    
    ' /* Call The TargetPath Property, Returning The Path Pointed To */
    GetShortcutPath = sc.TargetPath
End Function

Then to use the function, simply call it like so (using your source):

CommonDialog1.Filter = "Link Files (.lnk)|*.lnk"
CommonDialog1.ShowOpen
Text1.Text = GetShortcutPath(CommonDialog1.FileName)

A small warning, however, is that some security programs disable the windows scripting host (such as norton) and if this is done, then the code will not work (since WScript.Shell is windows scripting host). I'm researching an alternative method using API calls so that this can be avoided....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.