Select Shortcut path in VB.NET

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • remya1000
    New Member
    • Apr 2007
    • 115

    Select Shortcut path in VB.NET

    i'm using VB.NET 2003 application program.

    by using OpenFileDialog, we can select the file name or file path.
    Code:
            OpenFileDialog1.ShowDialog()
            pgmPath.Text = OpenFileDialog1.FileName
    by using FolderBrowserDi alog, we can select the folder name or folder path.
    Code:
             FolderBrowserDialog1.ShowDialog()
            folderPath.Text = FolderBrowserDialog1.SelectedPath
    is there a way i can select shortcut. i just want to select shortcut for a folder. but when i used FolderBrowserDi alog, it show only the folder list. its not showing the shortcut i have.

    for example: in desktop i have 4 folders, 1 EXE shortcut and 1 folder shortcut. but when i open FolderBrowserDi alog it shows only 4 folders, not showing the 2 shortcuts.
    a way i can show files that end with ".lnk" and select that shortcut. is there a way i can select shortcut's...

    and by using this shell command i tried to open the EXE's.
    Code:
    ProgramPath = "C:\Programs\Application1.exe"
    
    Shell(Chr(34) & ProgramPath & Chr(34), AppWinStyle.NormalFocus)
    and it works fine with all the EXE to get opened.

    but when i tried to open a shortcut using the same shell comment
    Code:
    ProgramPath = "C:\Programs\App.lnk"
    
    Shell(Chr(34) & ProgramPath & Chr(34), AppWinStyle.NormalFocus)
    error occurs... "File Not Found"

    is there a way i can open the shortcut.

    if anyone have any idea how to select shortcut (files that end with ".lnk") and a way i can open the shortcut, please help me. if you can provide any help, then that will be great help for me...

    Thanks in advance.
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    For the first part:
    Use the OpenFileDialog and set the filter to *.lnk maybe?
    That should show folders and files that end in .lnk (shortcuts?)

    To address the second part:
    You should not be using old VB commands in a net project (if you can avoid it). And in this case you can. The Process/ProcessStartInf o classes are the ones you should be usings.

    Comment

    • remya1000
      New Member
      • Apr 2007
      • 115

      #3
      Thanks for your reply and help.

      as you said i tried OpenFileDialog. its showing the Shortcut file. but when i select any shortcut file, it's going inside the shortcut folder. not able to select the shortcut file.

      for example: if you have shortcut file called "Shortcut of App". so if you select that, its showing the App folder and we need to select anything inside that. but not able to select the App.lnk.

      if i have "shortcut to App" in DeskTop or anywhere else and if i need to select that, how come i do that.

      if you have any idea how to do this, please help me and if you can provide an example, then that will be great help for me.

      Thanks in Advance

      Comment

      • anijos
        New Member
        • Nov 2008
        • 52

        #4
        Try this

        if (OpenFileDialog .FileName.ToLow er().EndsWith(" .lnk"))
        {
        ShellShortcut shortcut = new ShellShortcut(O penFileDialog.F ileName);
        String FileName = shortcut.Path;
        String Arguments= shortcut.Argume nts;
        String WorkingDirector y = shortcut.Workin gDirectory;
        }

        AniJos

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          You need to se the DereferenceLink s property of your OpenFileDialog to the correct value I think

          Comment

          • remya1000
            New Member
            • Apr 2007
            • 115

            #6
            Thank for you help anijos and Plater.

            As you said i tried this code...
            Code:
                    OpenFileDialog1.Filter = "(*.LNK;*.EXE)|*.lnk;*.exe"
                    OpenFileDialog1.DereferenceLinks = False
                    OpenFileDialog1.ShowDialog()
            so now it allow to select .exe or .lnk files. now i'm able to select .lnk files...

            That worked... Once again thanks a lots for your help...

            Comment

            Working...