How can I get the current user directory?

前端 未结 9 1112
说谎
说谎 2020-11-27 13:33

Using this:

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

I get this output:

\"C:\\\\Documents and S         


        
9条回答
  •  生来不讨喜
    2020-11-27 14:00

    Environment.GetEnvironmentVariable("userprofile")
    

    Trying to navigate up from a named SpecialFolder is prone for problems. There are plenty of reasons that the folders won't be where you expect them - users can move them on their own, GPO can move them, folder redirection to UNC paths, etc.

    Using the environment variable for the userprofile should reflect any of those possible issues.

提交回复
热议问题