Friday, June 06, 2008

Quick note on Temp File.

Quite often we would need to temporary files in C# and having to delete them once we are done with its usage. And it is not uncommon that we tend to forget write code to delete the file we created. There is a constructor in File Class which makes our life easier.

FileStream fs = File.Create(@"c:\anuviswan.txt", size, FileOptions.DeleteOnClose);

That's it and we can forget about deleting it later on. A small thing, but quite useful for people as forgetful like yours truly.