Click here to Skip to main content
15,886,071 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have zip files saved in database as base64 string.
I am able to extract files from those base64 string zip but I could not able to extract the folders and files inside the folders.

Please also let improve the code if there is best way to achieve this.

Down below is my code.

What I have tried:

byte[] dataFromBlob = item.BlobData;

                        using (MemoryStream ms = new MemoryStream(dataFromBlob))
                        {
                            using (ZipArchive zipArchive = new ZipArchive(ms))
                            {
                                foreach (var entry in zipArchive.Entries)
                                {
                                    using (var ims = new MemoryStream())
                                    {
                                        if (!entry.FullName.Contains("."))
                                        {
                                           string entryfullname = entry.FullName.Substring(0, entry.FullName.Length - 1);
                                            //entry.Open().CopyTo(ims);
                                            //File.WriteAllBytes(filePath + entryfullname, ims.GetBuffer());
											
											I do not know how do I read files from inside this entryfullname which is a folder and inside the folder there are files. 
                                        }
                                        else
                                        {
                                            entry.Open().CopyTo(ims);
                                            File.WriteAllBytes(filePath + entry.FullName, ims.GetBuffer());
                                        }
                                       
                                    }

                                }
                            }
Posted
Updated 20-Apr-20 4:58am
Comments
istudent 20-Apr-20 11:26am    
this is how i did it. But I think the solution may be error prone.
else if (entry.FullName.Contains("/") && entry.FullName.Contains("."))
{
var subdir = entry.FullName.Substring(0, entry.FullName.LastIndexOf("/"));

var fp = filePath + subdir + "\\";
Directory.CreateDirectory(fp);

entryName = entry.FullName.Substring(entry.FullName.LastIndexOf("/") + 1);

entry.Open().CopyTo(ims);
File.WriteAllBytes(fp + entryName, ims.GetBuffer());
}
Patrice T 20-Apr-20 11:49am    
Use Improve question to update your question.
So that everyone can pay attention to this information.

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900