Using the .net framework you have the option to create temporary files with
Path.GetTempFileName();
The MSDN doesn’t tell us what happens to temporary files. I remember reading somewhere that they are deleted by the OS when it gets a restart. Is this true?
If the files aren’t deleted by the OS, why are they called temporary? They are normal files in a normal directory.
The short answer: they don’t get deleted.
The long answer: The managed
Path.GetTempFileName()method calls the native Win32APIGetTempFileName()method, like this:The documentation for the native method states:
I have found a great article called ‘Those pesky temp files’ (Archived Oct. 2007) that starts from basics and touches some less obvious problems of handling temporary files, like:
FileOption.DeleteOnCloseand let the kernel deal with it)FileAttributes.Temporary)C# Code from article: