Programmatically create shortcuts for folders in Windows

回眸只為那壹抹淺笑 提交于 2019-12-13 08:58:46

问题


I have a folder A and a folder B. For each subfolder inside A I need to check if B contains a link to that subfolder. If not, I need to create it.

I'm currently creating the links using the code found on this page: Creating a file shortcut (.lnk) My problem is that this code always creates a file shortcut, not a folder shortcut, so if I try to open the shortcut it does not open the corresponding folder. Anyone knows how to create folder shortcuts instead?


回答1:


I'll answer my own question because I found lots of people asking this on the web and nobody providing an answer.

I found through trial and error that if you use the Path.GetFullPath method to calculate the value to assign to the TargetPath property, the output is in a format that's recognized as a folder path, so the system will automatically identify it as a folder shortcut and assign the corresponding icon.



来源:https://stackoverflow.com/questions/31429067/programmatically-create-shortcuts-for-folders-in-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!