public IActionResult GerarCsvNewsletter() { List <NewsletterEmail> newsletters = _newsletterRepository.ObterTodasNewsletters(); string Dir = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "uploads", "temp", "newsletter.csv"); using (StreamWriter sw = new StreamWriter(Dir)) { foreach (var newsletter in newsletters) { sw.WriteLine(newsletter.Email); } } byte[] bytes = System.IO.File.ReadAllBytes(Dir); return(File(bytes, "application/octet-stream", "newsletter.csv")); }