Windows Phone Developers

Thursday, October 30, 2008

How to get Temporary Folder using .NET (C#)

How to get path of the current system's temporary folder using .NET (C#)

Temporary folders are useful to store simple logs during execution of the program. It is also used for storing the decompressed files before any operation. The folder location varies from OS to OS. The following C# snippet would help in retrieving the Temporary folder path

string sPath;

sPath = Path.GetTempPath();

Console.WriteLine("Temporary Path := " + sPath );

Temporary Folder using .NET (C#), C# Temporary Folder, C# Temp Folder, .NET Temporary Folder, .NET Temp Folder

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

8 comments:

  1. Dim temp as String = System.IO.Path.GetTempPath

    Thats what im using, thanks btw!

    ReplyDelete
  2. Thats will resolve to the current USER temp folder if it exists. How can I retrieve the SYSTEM temp folder (ex: C:\Windows\Temp) from a program running in user land.

    ReplyDelete
    Replies
    1. Hi,
      When you are using a different user (as impersonation) or using a system user you could use LogonUser and LoadUserProfile.
      LogonUser changes the credentials, but, when you are trying GetTempPath you will receive the "old" temp path.
      With the new user (the impersonated one) is it possible to not have access to the obtained path.

      Kind regards,
      Radu Cosoveanu

      Delete
  3. OK, do you not understand how this is useless if you don't show the class that it's in or what you're importing? Thanks for nothing.

    ReplyDelete
  4. ^ the anonymous above needs to learn how to use google and msdn

    ReplyDelete
  5. ^Also it is stated in the very first comment...
    Thanks shasur

    ReplyDelete