public void ProcessRequest(HttpContext context)
        {
            response = context.Response;
            request  = context.Request;


            try
            {
                EmployeesWP wp        = new EmployeesWP();
                var         Employees = wp.GetData();
                using (SectionReport1 report = new SectionReport1(Employees))
                {
                    report.Run();
                    ToStream(report);
                }
            }
            catch (Exception ex)
            {
                // throw error to report
                using (ReportErrors report = new ReportErrors())
                {
                    report.UserData = ex.Message;
                    report.Run();
                    ToStream(report);
                }
            }
        }
Beispiel #2
0
        public void ProcessRequest(HttpContext context)
        {
            HttpResponse rs        = context.Response;
            EmployeesWP  wp        = new EmployeesWP();
            var          Employees = wp.GetData();

            try
            {
                byte[] Data;
                using (MemoryStream ms = new MemoryStream())
                {
                    using (StreamWriter writer = new StreamWriter(ms))
                    {
                        var stringHeader = "";
                        foreach (var property in Employee._Properties)
                        {
                            stringHeader += property.Name + ",";
                        }
                        writer.WriteLine(stringHeader);
                        foreach (var employee in Employees)
                        {
                            var stringValues = "";
                            foreach (var property in Employee._Properties)
                            {
                                stringValues += property.GetValue(employee, null).ToString() + ",";
                            }
                            writer.WriteLine(stringValues);
                        }
                    }
                    Data = ms.ToArray();
                }
                rs.ContentType = "application/csv";
                rs.AddHeader("Content-Length", Data.Length.ToString());
                rs.AddHeader("Content-Disposition", "inline; filename=MyFile.csv");
                rs.BinaryWrite(Data);
            }
            catch (Exception ex)
            {
                rs.Write(ex.Message);
            }
        }