Posted by: Cirilo Meggiolaro | 04/7/2009

Tip of the day #175 – Temp files easily

There are three useful static methods for those that need to work with temporary files. All methods are available under the System.IO.Path class;


  • The GetTempFileName method creates a zero-byte file with the extension .tmp in the local settings folder for the user and retrieves the full path as string:

// Output: C:\Documents and Settings\Cirilo\Local Settings\Temp\tmp302.tmp


  • The GetRandomFileName method returns a string that may be used as the name of a temporary folder or file.

// Output: 3iojffds.rv0


  • The GetTempPath method returns a string with the path of the local settings temporary folder.

// Output: C:\Documents and Settings\Cirilo\Local Settings\Temp\

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: