0

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

pardeep dhingra
  • 137
  • 1
  • 2
  • 7
  • I don't understand. Your WCF service is receiving a series of bytes that already constitute a zip file and you want to know how to save those bytes to disk? Or are you wishing to extract the contents of the zip file to disk? Needs more clarification. – Chris Dec 01 '12 at 14:55
  • I need to create the Zip file from the input bytes and save it on the disk and extract it – pardeep dhingra Dec 01 '12 at 15:03
  • method accept the byes. i need to convert into the zip file and save it on the disk and extract it – pardeep dhingra Dec 01 '12 at 15:14
  • see here for writing the byte array to disk http://stackoverflow.com/questions/381508/can-a-byte-array-be-written-to-a-file-in-c and here for extraction http://stackoverflow.com/questions/836736/unzip-files-programmatically-in-net – Luke Baughan Dec 01 '12 at 19:24

2 Answers2

1

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.
Alexander Stepaniuk
  • 6,217
  • 4
  • 31
  • 48
0

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.

w5l
  • 5,341
  • 1
  • 25
  • 43