I'm building a custom open file dialog and want to display the same list of favorites that appears in the left pane of a Windows Explorer dialog. How do I get a list of Windows Explorer Favorites shortcuts (*.lnk)?
Asked
Active
Viewed 192 times
1 Answers
0
The Windows Explorer Favorites
shortcuts are are stored in {SystemDrive}:\users{AccountName}\links. So, something like this will do it in C#
string pathToLinks = Environment.GetEnvironmentVariable("USERPROFILE") + "\\Links";
string[] fileEntries = Directory.GetFiles(pathToLinks, "*.lnk);

VA systems engineer
- 2,856
- 2
- 14
- 38
-
1Use `Environment.GetFolderPath(Environment.SpecialFolder.Favorites)` instead of `Environment.GetEnvironmentVariable("USERPROFILE") + "\\Links"` due to the fact that the user could have modified his favorites location – Tobias Brohl Apr 04 '18 at 19:33
-
`Environment.GetFolderPath(Environment.SpecialFolder.Favorites)` returns the location of Internet Explorer browser Favorites (not the list of favorites that appears in the left pane of a Windows Explorer dialog). I'm not sure if the location of Windows Explorer Favorites (`%USERPROFILE%\Links`) can be changed – VA systems engineer Apr 05 '18 at 12:52
-
wouldn't you do Directory.GetFiles(pathToLinks, "*.lnk); to filter instead of filtering in the loop? – Ctznkane525 Apr 06 '18 at 00:55
-
@NovaSysEng [You can change the location](https://drive.google.com/open?id=1IL16fMMr11NpaOjygbQQJgalCtm0X9sw) but there is a (quite complicated) solution: https://stackoverflow.com/a/27987197/6730162 – Tobias Brohl Apr 06 '18 at 21:16
-
1@TobiasBrohl Thanks - I'll take a look and I'll design my application to let the user browse to the location of their choice (with "USERPROFILE") + "\\Links" being the default if it exists) and set it as a default for my app – VA systems engineer Apr 07 '18 at 22:18