How to get path to user document in C # wpf

In my c # wpf application, I want to get a login to enter my documents path. I am using the following code.

string myDocumentPath = System.IO.Path.Combine(Environment.ExpandEnvironmentVariables("%userprofile%"), "Documents");

But when you start the wpf application using "Run as administrator", I got the path to the "Administrator" document using the code above.

Are there any other problems for this problem? Please accept any idea or advice.

+4
source share
1 answer

You must use Environment.GetFolderPath()to get the folders of the environment. In particular, use Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)one that will provide you with the My Documents folder (now simply called the Documents) for the user in whom the application is running.

+12

All Articles