Currently I have this problem, I am developing an MVC application for selling photos, I have a zip file that weighs 50mb that contains a list of photos, I want that when I press a button it will split that file into several zip files that weigh 10mb, try to do it by my account but the only thing I achieved is that it recreated the file with the same weight, that is, 50mb.
I tried to do the following: unzip the zip file and save it in a folder, I declared a variable to establish the maximum that each zip would have, that is, 10mb, and I did a do while loop to create the zip with the files that I saved in the folder as long as the weight of the zip that I am creating did not exceed 10mb and I was accumulating that weight to start doing the validation.
researching I found this link but it is not entirely clear to me
Split zip file using DotNetZip Library
[HttpPost]
public IActionResult GenerateCompressFiles()
{
string dateCapture = DateTime.Now.ToString("ddMMyyyy");
string timeCapture = DateTime.Now.ToString("hhmmss");
string directory = Path.Combine(_env.ContentRootPath, "Uploads");
string outputDirectory = Path.Combine(_env.ContentRootPath, "Uploads/ZipTest");
if (!Directory.Exists(directory)) Directory.CreateDirectory(directory);
string curFile = $"{directory}/MatiposExperencias-5345435435454.zip";
string zipFile = $"{directory}/MatiposExperencias-{dateCapture}{timeCapture}.zip";
var fileInfo = new FileInfo(zipFile);
using (ZipFile zip = ZipFile.Read(curFile))
{
zip.ExtractAll(outputDirectory, ExtractExistingFileAction.OverwriteSilently);
}
do
{
//Create A New Zip Archive
using (ZipFile zipDest = new ZipFile())
{
zipDest.AddFiles((System.IO.Directory.EnumerateFiles(outputDirectory)), false, ""); //This will add the files to the root
zipDest.Save(zipFile);
}
_currentArchiveSize += fileInfo.Length;
} while (_currentArchiveSize >= _maxArchiveSize
|| _currentArchiveSize + fileInfo.Length >= _maxArchiveSize);
return RedirectToAction("Index","Home");
}