Beispiel #1
0
        public async Task <IActionResult> GetExport(int iMonat)
        {
            var contentRootPath = _env.ContentRootPath;

            using (ZipFile zip = new ZipFile())
            {
                zip.AlternateEncodingUsage = ZipOption.AsNecessary;
                zip.AddDirectoryByName("Files");


                //Set the Name of Zip File.
                string zipName      = String.Format("Zip_{0}.zip", DateTime.Now.ToString("yyyy-MMM-dd-HHmmss"));
                var    memoryStream = new System.IO.MemoryStream();
                var    file         = System.IO.Path.Combine(contentRootPath, "MonthlyReposrt");
                AccountDto.ProcessWrite(_context, iMonat, file);
                zip.AddFile("MonthlyReposrt" + ".csv", "Files");

                using (var stream = new FileStream(file + ".csv", FileMode.Open))
                {
                    await stream.CopyToAsync(memoryStream);
                }

                //Save the Zip File to MemoryStream.
                zip.Save(memoryStream);

                memoryStream.Position = 0;
                return(NoContent());
            }
        }