Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should we close HttpPostedFile.Inputstream, once we are done using it?

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?

like image 668
surya Avatar asked Feb 16 '12 18:02

surya


2 Answers

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.

like image 176
James Gaunt Avatar answered Oct 06 '22 00:10

James Gaunt


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.

like image 38
raveturned Avatar answered Oct 05 '22 22:10

raveturned