Luke Smith Write today, wrong tomorrow

Remember to Close() after you Flush()

I'm not talking about closing the toilet lid (and not just putting the seat down as
women seem to think is acceptable!).


I've just been pulling my hair out over why a zip file generated using SharpZipLib was
being corrupted when returned from a webpage, saving to disk on the server worked
flawlessly. The file sent to the client was approximately 7kb larger than the one
saved on the server.

Now usually I use the using statement to dispose of any objects that use resources
but for some reason I wasn't calling Response.Close() in my method (Close() just
calls Dispose(true)).

What's even more annoying is there was the case of "it worked last week, why isn't
it working anymore???". I don't remember putting Response.Close() in the first place,
let alone deleting it at somepoint.

So please remember to Close() after you Flush(),
it's only polite.

comments powered by Disqus