How can I get the current user directory?

前端 未结 9 1104
说谎
说谎 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:02

    May be this will be a good solution: taking in account whether this is Vista/Win7 or XP and without using environment variables:

    string path = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)).FullName;
    if ( Environment.OSVersion.Version.Major >= 6 ) {
        path = Directory.GetParent(path).ToString();
    }
    

    Though using the environment variable is much more clear.

提交回复
热议问题