pardeep dhingra
pardeep dhingra

Reputation: 137

Create ZIp files from the bytes

I need to create a WCF method that accept a bytes array of the zip file contains the multiple pdf files and create the Zip files from the input bytes and save it in any folder of my application.

I am using WCf application.

Can any one help me ...

Thanks

Upvotes: 0

Views: 673

Answers (2)

w5l
w5l

Reputation: 5746

What do you really want to do here? You write that you want to get a Zip file from service and save it to disk (basicly: get a file through wcf service). Probably you want the contents of the zipfile instead?

For this you need a library to handle zip files, I suggest DotNetZip. To my knowledge DotNetZip can load from File and Stream as well as byte arrays. If not, you could create a stream from the byte array and pass that into the zip library.

Stream stream = new MemoryStream(byteArray);

For extracting and other operations, please read the manual on whichever zip library you choose.

Should you really just want to save a file from your byte array:

File.WriteAllBytes(string path, byte[] byteArray);

Either way, as @Alexander Stepaniuk suggests, you might be better off using a stream in your service, rather than passing byte arrays, read his post and links too.

Upvotes: 0

Alexander Stepaniuk
Alexander Stepaniuk

Reputation: 6408

I'd suggest the following:

  1. Pass file as Stream to WCF method rather than as a byte array. See Large Data and Streaming for details.
  2. You probably don't need to save unziped file on the disc to extract it. Can you take a look at the API of the unzipping library you use? Probably it can unzip data directly from the Stream. E.g. SharpZipLib can.

Upvotes: 1

Related Questions