none
C#: what "Path.GetTempPath()" suppose return? RRS feed

  • Question

  • We just notice that  Path.GetTempPath()return different temp folder on Windows XP and Windows 7.

    When mouse over the "GetTempPath()" function, it indicates that "Return path of the current system temporary folder".

    In windows 7, it returns the "User variable for "login user"

    such as "%USERPROFILE%AppData\Local\Temp"

    In windows XP, it returns the system variables TEMP folder such as "C:\windoes\TEMP".

    What function we should call to make it return consist?

    1) System variable TEMP folder or

    2) User variable TEMP folder

    thx!


    JaneC

    Thursday, January 3, 2013 8:12 PM

Answers

  • Hi Reed,

    Thanks for replying our question.

    When you mention "user the appropriate temp path for the operating system", what do you mean? Thx!


    JaneC

    GetTempPath() returns the location you should use for the operating system is running.  On Windows XP, this is often C:\Windows\Temp - as you discovered.  

    What I meant by that was that you should just use what it returns, and not worry about where it's located.  It will always return the correct folder.


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Thursday, January 3, 2013 9:21 PM
    Moderator

All replies

  • The two operating systems are designed differently, which is why this method exists.  You should use the appropriate temp path for the operating system where you are running, and not worry about where it's located.  (You can, actually, configure your system to use a completely different temp path, in which case, GetTempPath() would return that path.)


    By using Path.GetTempPath(), your application will be a good citizen on the user's system, no matter which OS they're using.


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Thursday, January 3, 2013 8:29 PM
    Moderator
  • Hi Reed,

    Thanks for replying our question.

    When you mention "user the appropriate temp path for the operating system", what do you mean? Thx!


    JaneC

    Thursday, January 3, 2013 9:17 PM
  • Hi Reed,

    Thanks for replying our question.

    When you mention "user the appropriate temp path for the operating system", what do you mean? Thx!


    JaneC

    GetTempPath() returns the location you should use for the operating system is running.  On Windows XP, this is often C:\Windows\Temp - as you discovered.  

    What I meant by that was that you should just use what it returns, and not worry about where it's located.  It will always return the correct folder.


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Thursday, January 3, 2013 9:21 PM
    Moderator
  • Hi Reed,

    Thanks for replying our question.

    When you mention "user the appropriate temp path for the operating system", what do you mean? Thx!


    JaneC

    Please mark the answer(s) which actually answer your question as the appropriate answer.

    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Thursday, January 3, 2013 9:51 PM
    Moderator