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!).

Anyway…

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.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

Please log in to WordPress.com to post a comment to your blog.

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.