By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,306 Members | 1,621 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,306 IT Pros & Developers. It's quick & easy.

Select Shortcut path in VB.NET

100+
P: 115
i'm using VB.NET 2003 application program.

by using OpenFileDialog, we can select the file name or file path.
Expand|Select|Wrap|Line Numbers
  1.         OpenFileDialog1.ShowDialog()
  2.         pgmPath.Text = OpenFileDialog1.FileName
  3.  
by using FolderBrowserDialog, we can select the folder name or folder path.
Expand|Select|Wrap|Line Numbers
  1.          FolderBrowserDialog1.ShowDialog()
  2.         folderPath.Text = FolderBrowserDialog1.SelectedPath
  3.  
is there a way i can select shortcut. i just want to select shortcut for a folder. but when i used FolderBrowserDialog, 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 FolderBrowserDialog 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.
Expand|Select|Wrap|Line Numbers
  1. ProgramPath = "C:\Programs\Application1.exe"
  2.  
  3. Shell(Chr(34) & ProgramPath & Chr(34), AppWinStyle.NormalFocus)
  4.  
and it works fine with all the EXE to get opened.

but when i tried to open a shortcut using the same shell comment
Expand|Select|Wrap|Line Numbers
  1. ProgramPath = "C:\Programs\App.lnk"
  2.  
  3. Shell(Chr(34) & ProgramPath & Chr(34), AppWinStyle.NormalFocus)
  4.  
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.
Dec 8 '08 #1
Share this Question
Share on Google+
5 Replies


Plater
Expert 5K+
P: 7,872
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/ProcessStartInfo classes are the ones you should be usings.
Dec 8 '08 #2

100+
P: 115
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
Dec 8 '08 #3

P: 52
Try this

if (OpenFileDialog.FileName.ToLower().EndsWith(".lnk" ))
{
ShellShortcut shortcut = new ShellShortcut(OpenFileDialog.FileName);
String FileName = shortcut.Path;
String Arguments= shortcut.Arguments;
String WorkingDirectory = shortcut.WorkingDirectory;
}

AniJos
Dec 9 '08 #4

Plater
Expert 5K+
P: 7,872
You need to se the DereferenceLinks property of your OpenFileDialog to the correct value I think
Dec 9 '08 #5

100+
P: 115
Thank for you help anijos and Plater.

As you said i tried this code...
Expand|Select|Wrap|Line Numbers
  1.         OpenFileDialog1.Filter = "(*.LNK;*.EXE)|*.lnk;*.exe"
  2.         OpenFileDialog1.DereferenceLinks = False
  3.         OpenFileDialog1.ShowDialog()
  4.  
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...
Dec 9 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.