If I create some file using Path.GetTempPath() - does it automatically get deleted at some stage, or is it up to me to delete it?
Hi there.
No, you will need to manually delete the file. Path.GetTempPath() just gives you the folder path to the temp folder.
Cheers. Jas.
if you use Path.GetTempFileName() the temporary file will indeed be removed by windows the next time the machine is rebooted.
Basically if your application does not delete a file it will still be there until your application removes it and you should manage files your app creates based on that idea.
That said, once the file is closed you must always allow for the fact that it may not be there next time you want it and that you may need to recreate it. For example, Windows has a "disk cleanup tool" which may be run when space gets low, when directed by a user, or on a schedule...
FileOptions.DeleteOnClose
will cause the file to be deleted automatically when closed. This also works if the program is terminated by an exception.