segunda-feira, 20 de julho de 2015

CSVGeneration


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Lapuinka.Utils
{
    public class CSVGeneration
    {
        public static void Generate(System.Web.HttpResponse response, DataTable dataTable)
        {
            var revenda = "";

            response.Clear();
            response.AddHeader("content-disposition", string.Format("attachment;filename={0}_{1}.csv", revenda, DateTime.Now.ToShortDateString().Replace("/", "")));
            response.Charset = "utf-8";
            response.ContentType = "text/csv";

            var output = DataTableToCsv.ToCsv(dataTable);

            response.Output.Write(output.ToString());
            response.Flush();
            response.End();
        }      
    }
}

Postar um comentário