Get full path of file a shortcut link references


/ Published in: C#
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.