Should we close HttpPostedFile.Inputstream as soon as we finish using it?

I upload a file and directly load the input stream into one of my objects. My question is: should we close and reset it as soon as we finish processing it?

+7
source share
2 answers

You do not need to explicitly close it, resources allocated on your server are deleted when the request ends. See Final Note in MSDN docs.

http://msdn.microsoft.com/en-us/library/system.web.httppostedfile.aspx

However, if the question is that you should close it (or at least get rid of it), then I would say yes. Why not? It can release resources earlier than they would otherwise be released, and you know that you no longer need them.

+5
source

All objects that extend System.IO.Stream objects implement IDisposable. It would be best to put your input stream in a using block to make sure it is properly closed and removed even if an exception is thrown.

+3
source

All Articles