Drag and drop options

I am making a simple tool. If I drag n folders, folders into my form, it will automatically open the corresponding file and folder. Now I want to do this for .lnk files (shortcuts), if I dragged the .lnk file, it should open the target file.

0
source share
1 answer

Ok, this is just a layout, but you should get an idea ...

First add the link COM> Windows Script Host Object Model ' to your project.

Next, include the line ...

 using IWshRuntimeLibrary; 

In this example, I just used a list control, but I use what you need ... If you are handling the DragEnter event, you can get the file name passed as an argument. Then you can create a WshShell object to get the target link 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 does not handle shortcuts, etc., but it should give you a starter ... :)

+2
source

All Articles