Method for uploading and extracting a zip.
Note:-
1.Please provide the path for saving the zip,dont copy the same text as it given below.
2.Please do not change any syntax of method you have to only change the destination folder path .
public void Upload_And_Extract_ZIP()
{
if (FileUploadControlID.HasFile)
{
string filename = Path.GetFileName(FileUploadControlID.FileName);
string ext = Path.GetExtension(FileUploadControlID.FileName);
string Destination_Folder_Path = “Enter the full folder path where you want to save the zip”;
try
{
FileUploadControlID.SaveAs(Server.MapPath(Destination_Folder_Path);
string pathurl = Destination_Folder_Path + filename;
using (ZipInputStream s = new ZipInputStream(File.OpenRead(pathurl)))
{
ZipEntry theEntry;
while ((theEntry = s.GetNextEntry()) != null)
{
string directoryName = Path.GetDirectoryName(theEntry.Name);
string fileName1 = Path.GetFileName(theEntry.Name);
//…..creating directory for saving zip after extracting zip.
Directory.CreateDirectory(Destination_Folder_Path + “/” + filename);
// Extracting zip function is below………..
if (directoryName.Length > 0)
{
Directory.CreateDirectory(Destination_Folder_Path + “/” + filename + “/” + directoryName);
}
if (fileName1 != String.Empty)
{
using (FileStream streamWriter = File.Create(Destination_Folder_Path+ “/” + filename + “/” + theEntry.Name))
{
int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = s.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size);
}
else
{
break;
}
}
}
}
}
}
}
catch
{
throw;
}
}
}