Best way to get temp directory without PInvoke?

  • Thread starter Thread starter Charlie Calvert
  • Start date Start date
C

Charlie Calvert

Staying in managed code, what is the best way to get the temp directory
in C# .NET programming? I'm currently using this:

public static String GetTempDir()
{
return Environment.GetEnvironmentVariable("TEMP");
}

I wonder, is there a better solution? This one feels a little system and
OS dependant to me.

Thanks.

- Charlie
 
Hi Charlie,

You could try the GetTempPath() static method in the Path class
in the System.IO namespace.

String tempFolderPath = Path.GetTempPath();

Regards,
Aravind C
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top