AP.NET WEBAPI: Compress a CSV file and Send the Response as ZIP
WEB API: Compress a CSV file and Send the Response as ZIP In ASP.NET WEB API, we can create an API call for sending the file in response. Which means that the user can call an URL and gets the required file as a download. Zipping a file in earlier versions of dotnet framework 4.0 was quite lengthy (sometimes it has needed to use third part tools). From 4.5 on wards, we have an assembly for that task specifically with one single line of code. C# code for the API: We need to add reference of System.IO.Compression.FileSystem to the project and use the below using statement to make the ZIP statement work. using System.IO.Compression; Once the steps are done, need to map the directory to store the generated CSV file temporarily. Once mapping is done, write all text content the the file. Need to provide the final zip file name along its path (fully qualified file name). Zip.CreateFromDirectory is the important line to ZIP. It just takes the source folder contents, zips it and