Share via


System IO Compression exception

Question

Wednesday, February 28, 2018 4:15 PM

Hello,

Im sending zip files over TCP. When I try to extract them something happens and I can't understand why.

Every time, the first file is being saved and extracted, and then the second file I receive cannot be extracted, and this is the exception I get:
System.IO.IOException: An attempt was made to move the file pointer before the beggining of the file.
The title for the exception is that the main library is defective.

That's the code line with the problam:

System.IO.Compression.ZipFile.ExtractToDirectory(zip_path, extract_path);

Any suggestions for a solution?

(maybe the problam is somewhere else, basicly I want to know what can cause this kind of exception)

All replies (6)

Thursday, March 1, 2018 4:31 PM âś…Answered

Found the problam, thanks for the advises...


Wednesday, February 28, 2018 4:31 PM

Try opening the zip file from the system that created it, such as by opening it in the Files Explorer (Windows Explorer). If that works then open it in the system it has been sent to. Do both of those work?

Sam Hobbs
SimpleSamples.Info


Wednesday, February 28, 2018 6:11 PM

Post the code you're using to send and receive the file. Based upon the error it sounds like you are either reading too much data (which could be a problem on the sender or receiver side) or your receive code is not resetting itself in order to read the second file correctly.

Michael Taylor http://www.michaeltaylorp3.net


Wednesday, February 28, 2018 7:15 PM

You are replying to me but it is not my code so I can't post it.

I was going to suggest that some code be provided but then I decided to be methodical about it. Since Roy Jiny only posted the ExtractToDirectory code he seems to think the problem is there and if the file can't be opened by Windows then we know the problem is not with the ExtractToDirectory code.

Sam Hobbs
SimpleSamples.Info


Thursday, March 1, 2018 2:06 AM

Hello Roy,

I think the most likely reason is you are getting the damaged file, try to unzip files manually. If you open these file successfully, please provide more detailed code related to extract. If not, it indicates these file are damaged over transport.

Hope this would be helpful.

Best regards,

Neil Hu

MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].


Thursday, March 1, 2018 9:07 AM

So I read the replies and my code again, as I said Im not sure that the problam is in that specific line. There is a good posibility that it's in the sending and receiving proccess, which Im cheking now...

If I won't find the problam I'll upload this code too.
Thanks for now, I'll alert if I find the problam.