I often notice that they use search paths in different ways, but how do they differ (that is, work for different operating systems in some different way or what)?

What's the difference between

string environmentVariable = Environment.GetEnvironmentVariable("temp"); 

or simply

 string environmentVariable = Path.GetTempPath(); 

As well as interested in:

Console application and Windows Forms from .Net 2.0 work on all OS? : Starting from XP and ending with Win 10 ?!

  • .net 2.0 has been included with Windows since Vista. On XP it must be manually installed - PashaPash
  • @PashaPash on XP it went as part of one of the service packs - Pavel Mayorov
  • @PavelMayorov seems to be there was only .net 1.1 in SP2 / SP3, and then in the form of additional. Component: blogs.msdn.microsoft.com/astebner/2007/03/14/… - PashaPash
  • @PashaPash So on XP there will be problems with the launch of Winforms applications? - GooliveR
  • @ArteS will have no problems, but you will have to upgrade XP to SP2 and deliver .net 2.0 to it. - PashaPash

1 answer 1

Environment.GetEnvironmentVariable("temp") will simply return the value of the environment variable named temp

Path.GetTempPath will return the first existing value from the following list:

  1. The path specified in the TMP environment variable.
  2. The path specified in the TEMP environment variable.
  3. The path specified in the USERPROFILE environment variable.
  4. Windows directory.

... so it is safer and safer than calling GetEnvironmentVariable("temp") .

By the way, this is directly stated in MSDN using the Path.GetTempPath method Path.GetTempPath