Hello guys!
I'm facing a problem with SharpZipLib.Zip in C# with Mac. When i download a zip that contain a folder in PC it works fine, but when i download in mac, instead of getting files with full path, instead of files inside the folders. example: //Test//Test.txt ---> Test/Test.txt as file.
I searched in Google, and found this: SharpZipLib's FastZip doesn't unzip directories on Mac Not helped me that much, the zip created on the fly. My code looks like the following: (JMSentFile is my class :)) Thanks for help!
ZipOutputStream zip1 =newZipOutputStream(outStream);ZipConstants.DefaultCodePage=Encoding.UTF8.CodePage;
zip1.UseZip64=UseZip64.Off;
zip1.SetLevel(0);foreach(JMSentFile F in FL){stringSentFile_FileName=string.Empty;stringSentFile_Status=string.Empty;stringSentFile_OriginalFileName=string.Empty;stringSentFile_Path=string.Empty;
bool IsFolder=false;if(F !=null){if(!string.IsNullOrEmpty(F.SentFile_FileName)){SentFile_FileName= F.SentFile_FileName;}if(!string.IsNullOrEmpty(F.SentFile_Status)){SentFile_Status= F.SentFile_Status.ToUpper();}if(!string.IsNullOrEmpty(F.SentFile_OriginalFileName)){SentFile_OriginalFileName= F.SentFile_OriginalFileName.Replace(" ","_");}if(!string.IsNullOrEmpty(F.SentFile_FolderPath)){SentFile_Path= F.SentFile_FolderPath;IsFolder=true;}}//Getting file stream data.stringFilePath=string.Format("{0}\\{1}", path,SentFile_FileName);if(!string.IsNullOrEmpty(FilePath)&&File.Exists(FilePath)&&SentFile_Status!=Status.SIZE_ERROR.ToString()){FileStream inStream =File.Open(FilePath,FileMode.Open,FileAccess.Read,FileShare.Read);ZipEntry entry =null;if(IsFolder){
entry =newZipEntry(string.Format("{0}\\{1}",SentFile_Path,SentFile_OriginalFileName));}else{
entry =newZipEntry(SentFile_OriginalFileName);}
entry.DateTime=DateTime.Now;
zip1.PutNextEntry(entry);int bytesRead = inStream.Read(buf,0, buf.Length);while(bytesRead >0&& context.Response.IsClientConnected){
zip1.Write(buf,0, buf.Length);
zip1.Flush();
bytesRead = inStream.Read(buf,0, buf.Length);}
inStream.Close();
zip1.CloseEntry();}}
zip1.Finish();
zip1.Flush();
outStream.Flush();
zip1.Close();