Hi everyone
I'm doing a simple tool. If I drag n drop files ,folders into my form it will automatically open the corresponding file and folder. Now I want to do it for .lnk
files(shortcuts) if I drag a .lnk
file, it must open the target file.
Hi everyone
I'm doing a simple tool. If I drag n drop files ,folders into my form it will automatically open the corresponding file and folder. Now I want to do it for .lnk
files(shortcuts) if I drag a .lnk
file, it must open the target file.
Okay this is a simple mock up but you should get the idea...
First add the COM 'Windows Script Host Object Model' reference to your project.
Next include the line...
using IWshRuntimeLibrary;
For this example I just used a list box control but use what ever you want... If you handle the DragEnter event, you can get the file name passed as an argument. You can then create a WshShell object to get the links target path.
private void listBox1_DragEnter(object sender, DragEventArgs e)
{
String[] fileName = (String[])e.Data.GetData("FileName");
WshShell shell = new WshShell();
IWshShortcut link = (IWshShortcut)shell.CreateShortcut(fileName[0]);
String targetPath = link.TargetPath;
listBox1.Items.Add(targetPath);
}
The code doesn't handle non shortcuts etc but it should give you a starter... :)