What determines the return value of Path.GetTempPath()?

后端 未结 6 405
忘了有多久
忘了有多久 2020-12-08 13:20

Currently, I use Path.GetTempPath() to figure out where to write my log files, but recently I came across a user\'s machine where the path returned was not what

6条回答
  •  臣服心动
    2020-12-08 13:46

    (Using Reflector) Path.GetTempPath() ultimately calls the Win32 function GetTempPath (from kernel32.dll). The MDSN docs for this state:

    The GetTempPath function checks for the existence of environment variables in the following order and uses the first path found:

    • The path specified by the TMP environment variable.
    • The path specified by the TEMP environment variable.
    • The path specified by the USERPROFILE environment variable.
    • The Windows directory.

    Note that they also state that it doesn't check whether or not the path actually exists or can be written to, so you may end up trying to write your log files to a path that doesn't exist, or one that you cannot access.

提交回复
热议问题