c# - Processing HttpPostedFile.InputStream before saving using SaveAs() -


i need check if file compressed before saving it. have created following extension method check if file compressed using zipfile (from sharplibzip library):

public static bool iscompressed(this httppostedfile postedfile) {     stream stream = postedfile.inputstream;      using (var zipfile = new zipfile(stream))     {         return zipfile.testarchive(true);     } } 

the problem when call httppostedfile.saveas() saves file 0kb:

if(uploadedfile.iscompressed()) {     uploadedfile.inputstream.seek(0, seekorigin.begin);     uploadedfile.saveas(physicalzipfile.fullname); } 

this has using stream in iscompressed(). have tried seeking beginning before saving problem remains.

could please explain problem here?

for stumbles upon this... here solution:

using ilspy decompiled assembly find zipfile.dispose() closes stream. there other cleanup code wouldn't recommend not disposing of zipfile instance.

on other hand, ziparchive (system.io.compression) has following overloaded constructor:

public ziparchive(stream stream, ziparchivemode mode, bool leaveopen) 

setting leaveopen true leave stream open after instance has been correctly disposed.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

How can I fetch data from a web server in an android application? -

jquery - How can I dynamically add a browser tab? -