Reading and processing zip file

bczm8703

Member
Joined
Jan 21, 2014
Messages
7
Programming Experience
1-3
hi i am task to write a console application to get a zip file from the SFTP server, process the files and upload it to server

the folder structure zip file is

mainfile_20170412.zip
- firstFolder
- firstChild.zip
- file1.pdf
- file2.pdf
- file3.pdf
- file4.pdf​
- secondFolder
- secondChild.zip
- file5.pdf
- file6.pdf
- file7.pdf
- file8.pdf​

i am required to upload file1.pdf - file8.pdf into my Repository server

my code thus far
C#:
using System.IO.Compression;
...
using(ZipArchive archive = ZipFile.OpenRead("mainfile_20170412.zip"))
{
   foreach(ZipArchiveEntry entry in archive.Entries)
   {
        //how do i access firstChild.zip and secondChild.zip from here?
   }
}
 
You call the Open method of the ZipArchiveEntry to get a Stream and then you can treat it like any other Stream. For instance, if you want to extract the data and write it to a file then you can create a FileStream and then call CopyTo on your source Stream. If you want to upload the data to a remote server then you can use a WebRequest to get a Stream and CopyTo that.
 
hi i am task to write a console application to get a zip file from the SFTP server, process the files and upload it to server

the folder structure zip file is

mainfile_20170412.zip
- firstFolder​
- firstChild.zip​
- file1.pdf​
- file2.pdf​
- file3.pdf​
- file4.pdf​
- secondFolder​
- secondChild.zip​
- file5.pdf​
- file6.pdf​
- file7.pdf​
- file8.pdf​

i am required to upload file1.pdf - file8.pdf into my Repository server

my code thus far
C#:
using System.IO.Compression;
...
using(ZipArchive archive = ZipFile.OpenRead("mainfile_20170412.zip"))
{
   foreach(ZipArchiveEntry entry in archive.Entries)
   {
        //how do i access firstChild.zip and secondChild.zip from here?
   }
}

using (var archive = new ZipArchive(responseStream, ZipArchiveMode.Read))
{
watch.Stop();
var elapsedMs = watch.ElapsedMilliseconds;
foreach (var entry in archive.Entries)
{
using (var stream = entry.Open())
{
using (var reader = new StreamReader(stream))
{
while ((line = reader.ReadLine()) != null)
{
arr.Add(line);
}
}
}
}
}
 
Back
Top Bottom