0

I am downloading a zipped folder using DotNetZip, file is downloading && its extracting on windows but when i am trying to Un zip that zip folder, it is not opening. On mac machine?

//Define file Type
string fileType = "application/octet-stream";

//Define Output Memory Stream
var outputStream = new MemoryStream();

//Create object of ZipFile library
using (ZipFile zipFile = new ZipFile())
{
    //Add Root Directory Name "Files" or Any string name
    zipFile.AddDirectoryByName("Files");

    //Get all filepath from folder
    String[] files = Directory.GetFiles(Server.MapPath("/BillingReport"));
    foreach (string file in files)
    {
        string filePath = file;

        //Adding files from filepath into Zip
        zipFile.AddFile(filePath, "Files");
    }

    Response.ClearContent();
    Response.ClearHeaders();

    //Set zip file name
    Response.AppendHeader("content-disposition", "attachment; filename=BillingReport.zip");

    //Save the zip content in output stream
    zipFile.Save(outputStream);
}

//Set the cursor to start position
outputStream.Position = 0;

Array.ForEach(Directory.GetFiles(Server.MapPath("/BillingReport")), System.IO.File.Delete);

//Dispance the stream
return new FileStreamResult(outputStream, fileType);
Luuk
  • 12,245
  • 5
  • 22
  • 33
  • Did you try it from command line (`unzip filename`)? Try using a third party unarchiving software like `The unarchiver` https://theunarchiver.com – BenceL Feb 12 '21 at 18:46
  • No I not try yet. But is it be the good solution for all users? – Rajesh Vhadlure Feb 13 '21 at 05:33
  • I mean sometimes I can't even open zip files on my mac created by hand on windows. I haven't used this zip library yet, but using the native one, I had to play with the correct order of saving, disposing and seeking, you should try changing the order of these. I don't know why you opted to using this open source library when there is one by microsoft. I think it would be worth it to use that. see: https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.ziparchive?view=net-5.0 – BenceL Feb 13 '21 at 08:49
  • I want to download the zip file on client computer so that can use by client. – Rajesh Vhadlure Feb 13 '21 at 09:54
  • You should first create a working solution for yourself locally. If you can open a zipfile locally and read its contents, then it's only a small step to have it downloaded. – Luuk Feb 13 '21 at 10:03
  • I don't know what has to do anything with downloading in this problem. The problem is not with downloading that's for sure! As @Luuk said you should try it locally first. Just create a console app copy paste this code inside the main. Once you can open it successfully you can just copy it back into the server code. – BenceL Feb 13 '21 at 10:27
  • Yes. Its downloading successfully on windows. I found issue on mac. – Rajesh Vhadlure Feb 17 '21 at 02:21

0 Answers0