I have a WPF application that is run from a shortcut. Is there anyway I can access the directory location of the shortcut from within the WPF application?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
From what I understand you cannot do that.
When you click on the shortcut, Windows reads the path to the target executable and execute it just like when you directly click the .exe file (with additional parameters specified in the shortcut of course). Your WPF application has no idea whether it is started by direct clicking, from the command line or from a shortcut; hence cannot get the folder in which the shortcut resides.
If your question refers to .exe location than use Reflection as in the other answer.
Hope this help 🙂
Edit:
A trick I use to get it is to set the “Start in” field in the Properties of the shortcut to be the folder containing the shortcut then get it by
though it is not reliable at all as many factors tend to change the current working folder value and you need to set this for every shortcut you use 🙂