简体   繁体   中英

How to get login user's document path in C# wpf

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM