Search code examples
.nettemporary-files

Temporary files in .Net


I need to create some bitmaps and save them to the file system. For some reason the MScharting system wants it's background files supplies as paths in string form.

I'm dynamically creating the background image, although only a few times.

What's the best way to create these files and then clean them up?


Solution

  • Your best bet is to have a TemporaryFileManager that implements IDisposable; you ask it for temporary files, which it auto-generates and sticks in a temp directory somewhere, then they all get deleted when the TemporaryFileManager gets disposed, either by you or the finalizer (if you've implemented the disposable pattern correctly)