I am uploading a file and directly feeding Inputstream to one of my objects. My Question is should we close and flush it once we are done processing it?
You don't need to explicitly close it, the resources allocated on your server are disposed when the request ends. See the final remark in the MSDN docs.
http://msdn.microsoft.com/en-us/library/system.web.httppostedfile.aspx
However if the question is should you close it (or at least dispose of it) - then I'd say yes. Why not? It may release resources earlier than they would otherwise be released and you know you don't need them any more.
All objects that extend System.IO.Stream objects implement IDisposable. It would be best practice to put your Input stream in a using
block, to ensure it is properly closed and disposed even in the event of an exception being thrown.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With