Search code examples
c#temporary-files

What folder does Path::GetTempFileName Method save to?


I need to get the temp file to see what happened because the actual file is never output. However, I can't seem to find where the temp file is created.

I need to find this out without writing code or building the application because there are too many dependencies scattered all over the place. I would not be able to deploy a debug version.


Solution

  • That method returns the path of a temporary file. The path will tell you where its pointing.

    For example:

    Console.WriteLine(Path.GetTempFileName());
    

    produces:

    C:\Users\will\AppData\Local\Temp\tmp9BD5.tmp
    

    for me on this machine, because the TEMP environment variable is pointing to C:\Users\will\AppData\Local\Temp\

    But the whole point of a method like GetTempFileName is that you shouldn't have to care where the file ends up. On the off-chance that you do, you can always get there at command prompts or file-open dialogs by using %TEMP%