Last active
November 7, 2023 11:13
-
-
Save MichalGrzegorzak/6ed8215de5477909d601a7312626ccff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<byte[]> GenerateZipFileAsync() | |
{ | |
using (var memoryStream = new MemoryStream()) | |
{ | |
using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true)) | |
{ | |
await AddFileToZipAsync(archive, "HzImpAccountsT.csv", file.Accounts); | |
await AddFileToZipAsync(archive, "HzImpAcctContactsT.csv", file.Account_Contacts); | |
} | |
return memoryStream.ToArray(); | |
} | |
} | |
protected async Task AddFileToZipAsync<TData>(ZipArchive archive, string filename, IEnumerable<TData> data) | |
{ | |
var file = archive.CreateEntry(filename); | |
using (var entryStream = file.Open()) | |
using (var streamWriter = new StreamWriter(entryStream)) | |
{ | |
streamWriter.Write(csvData); | |
} | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment