I would like to get the target information from a shortcut file using my OOB application for Silverlight, so I'm going to make the following code to work in my Silverlight OOB. It seems I need to use P / Invoke to use Shell32.dll, but I'm not sure how I can use Folder, FolderItem and ShellLinkObject? Most links explain how I can use functions in .dll using P / invoke :( Please give me comments or sample code / links :)
public string GetShortcutTargetFile(string shortcutFilename)
{
string pathOnly = Path.GetDirectoryName(shortcutFilename);
string filenameOnly = Path.GetFileName(shortcutFilename);
Shell32.Shell shell = new Shell32.ShellClass();
Shell32.Folder folder = shell.NameSpace(pathOnly);
Shell32.FolderItem folderItem = folder.ParseName(filenameOnly);
if (folderItem != null)
{
Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink;
MessageBox.Show(link.Path);
return link.Path;
}
return String.Empty;
}
source
share