public ActionResult <Comment> Export() { var allComments = _commentService.GetList().Result; var csvByteArr = _csvService.ConvertToCSV(allComments); var fileName = $"comments-{DateTime.Now.ToFileTimeUtc()}.csv"; return(File(Encoding.UTF8.GetBytes(csvByteArr.ToString()), "text/csv", fileName)); }
public async Task <HttpResponseMessage> Export() { var allComments = await _commentService.GetList(); HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); result.Content = new StreamContent(new MemoryStream(_csvService.ConvertToCSV(allComments))); var fileName = $"comments-{DateTime.Now.ToFileTimeUtc()}.csv"; result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = fileName }; return(result); }