In my wpf C# application, I want to get login user's my documents path. I use the following code.
string myDocumentPath = System.IO.Path.Combine(Environment.ExpandEnvironmentVariables("%userprofile%"), "Documents");
But when run the wpf application with Run as Administrator, I got the Administrator's document path by using the above code.
Is there other funtion for this problem? Please any idea or advice.
You should use Environment.GetFolderPath()
for getting environment folders. In particular, use Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
, which will give you the "My Documents" (now simply called "Documents") folder for the user that the application is running under.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With