Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 693
ammoe Avatar asked Aug 28 '15 03:08

ammoe


Video Answer


1 Answers

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.

like image 58
willaien Avatar answered Oct 23 '22 02:10

willaien



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!