Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Documents folder path of current logged on user

Tags:

People also ask

What is the path where My Documents folder is present in your computer?

A shortcut to it is displayed directly on the user's desktop. The Windows NT family of operating systems set up the "My Documents" folder in the user's profile folder. In Windows XP and earlier, the path is \Documents and Settings\[user name]\My Documents\ (alias %USERPROFILE%\My Documents\ ) on boot volume.

What is the default path for documents for a specific user account in Windows 10?

The default paths are: Documents: %USERPROFILE%\Documents. Music: %USERPROFILE%\Music. Pictures: %USERPROFILE%\Pictures.


I'm developing a C# WinForms application. This application has the ability to update if an update is available on server. It's working fine, but only for an admin user.

The Application will check and apply update with the steps below if user doesn't have admin privileges:

  • When a normal user presses the "Check Update" button, application will check if any update is available on the server.
  • If an update is available, the application will confirm applying the update with a message box.
  • If the user presses "Yes" for apply update than it will prompt using the Windows default admin privileges required box.
  • If the current user has the user name and password of an admin user then they enter it and apply the update.

Problem

After an applied update (only for normal user) the application is running as an admin user and I'm trying to get the Documents folder path of current user. It gives me the Documents folder path of the admin user because of application is currently running as the admin user, but I want the Documents folder path of currently logged on user.

Question

How can I get the current logged on user's Documents folder if the application is running as an admin user?

Currently I am get Document folder path with below code.

Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)