Expand environment variable for My Documents

后端 未结 6 2105
星月不相逢
星月不相逢 2021-01-04 06:19

I know I can read environment variables like this:

Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

However, it would be r

6条回答
  •  被撕碎了的回忆
    2021-01-04 06:59

    No there is no environment variable for the MyDocuments special folder (the same is true for most members of the SpecialFolder enumeration).

    Check out this snippet, it might be exactly what you are searching for.

    It allows you to do something like that:

    string fullPath = SpecialFolder.ExpandVariables(@"%MyDocuments%\Foo");
    

    Note: SpecialFolder.ExpandVariables is a static method of a helper class introduced in the above snippet.

提交回复
热议问题