Пример #1
0
        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));
        }
Пример #2
0
        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);
        }