Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
4.67/5 (3 votes)
See more:
Hi People.

I'm developing a c# Win Application & need to point to some windows directory like a logged in user's temp directory.

How could I do this?
Does anyone have any idea, please?
Posted
Updated 29-Nov-10 22:31pm
v2
Comments
Dalek Dave 30-Nov-10 4:31am    
Edited for Readability.

C#
using System;
using System.IO;

namespace TempFolder
{
    class Program
    {
        static void Main(string[] args)
        {
            // Get temp path
            string strTempPath = Path.GetTempPath();
            Console.WriteLine("Temp path is {0}", strTempPath);

            // Get temp file
            string strTempFileName = Path.GetTempFileName();
            Console.WriteLine("Temp file name is {0}", strTempFileName);

            Console.ReadKey();
        }
    }
}
 
Share this answer
 
Use this for Get Temporary Directory path

MessageBox.Show(Path.GetTempPath().ToString());


namespace in
System.IO
 
Share this answer
 
Comments
Rod Kemp 30-Nov-10 5:43am    
GetTempPath() returns a string there is no need to call ToString() on it.
Rajesh Anuhya 30-Nov-10 6:06am    
OK.., Accepted..
Rajesh Anuhya 30-Nov-10 6:16am    
Please Leave a comment .., who is downvoing this...
Dalek Dave 30-Nov-10 6:17am    
I will add a comment, and a 5.

It is a good answer.

That should counteract the arse who downvoted you.
u can refrence temp variables easily. for ex '%temp%' redircts u to 'C:\Documents & Settings\<nt-id>\Local Setting\Temp' u can acccess tat path esily!
 
Share this answer
 
Comments
Dalek Dave 30-Nov-10 6:14am    
You are so desperate aren't you.
Rajesh Anuhya 30-Nov-10 6:15am    
well said
Pete O'Hanlon 30-Nov-10 6:43am    
And how would you reference the temp variable? What code would you use? I'm curious to see how you would solve this. It's no good just saying use %temp% - you haven't indicated to the OP how they would get environment variables in .NET.
DaveyM69 30-Nov-10 9:25am    
To complete the answer...
To obtain the value of TEMP you will need to do:
Environment.GetEnvironmentVariable("TEMP")

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900