Posted By

kyrathaba on 01/27/11


Tagged

shortcut target fullpath resolve


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

thastyle


Get full path of file a shortcut link references


 / Published in: C#
 

Add a reference to Microsoft Shell Controls and Automation to your project. Then add the method shown below:

  1. public string GetShortcutTargetFile(string shortcutFilename) {
  2. string pathOnly = System.IO.Path.GetDirectoryName(shortcutFilename);
  3. string filenameOnly = System.IO.Path.GetFileName(shortcutFilename);
  4.  
  5. Shell32.Shell shell = new Shell32.ShellClass();
  6. Shell32.Folder folder = shell.NameSpace(pathOnly);
  7. Shell32.FolderItem folderItem = folder.ParseName(filenameOnly);
  8. if (folderItem != null) {
  9. Shell32.ShellLinkObject link =
  10. (Shell32.ShellLinkObject)folderItem.GetLink;
  11. return link.Path;
  12. }
  13. return ""; // not found
  14. }

Report this snippet  

You need to login to post a comment.