I rebuilded it an now it works =>
public static class ExtractZipFileHelper
{
public static async Task<ResultHelper> ExtractZipFileCloudStorageAsync(CloudFileDirectory extractDirectory)
{
try
{
if (extractDirectory == null)
{
return ResultHelper.CreateResultHelper(false, "The parameter 'extractDirectory' is empty or NULL!");
}
return await ExtractZipFileAsync(extractDirectory);
}
catch (Exception ex)
{
return ResultHelper.CreateResultHelper(false, $"Error while extracting zip files: {ex.Message}");
}
}
private static async Task<ResultHelper> ExtractZipFileAsync(CloudFileDirectory extractDirectory)
{
try
{
var filesAndDirectories = await extractDirectory.ListFilesAndDirectoriesSegmentedAsync(null);
foreach (var item in filesAndDirectories.Results)
{
if (item is CloudFile cloudFile)
{
if (cloudFile.Name.EndsWith(".zip"))
{
using (MemoryStream memoryStream = new MemoryStream())
{
await cloudFile.DownloadToStreamAsync(memoryStream);
using (ZipArchive zipArchive = new ZipArchive(memoryStream))
{
foreach (ZipArchiveEntry entry in zipArchive.Entries)
{
CloudFile entryFile = extractDirectory.GetFileReference(entry.FullName);
using (MemoryStream entryStream = new MemoryStream())
{
using (Stream entryFileStream = entry.Open())
{
await entryFileStream.CopyToAsync(entryStream);
}
entryStream.Position = 0;
await entryFile.UploadFromStreamAsync(entryStream);
}
}
}
}
}
}
}
return ResultHelper.CreateResultHelper(true);
}
catch (Exception ex)
{
return ResultHelper.CreateResultHelper(false, $"Error while extracting zip files: {ex.Message}");
}
}
}