Izenda, LLC

Ad Hoc Reports & Dashboards for ASP.NET Apps

Free Trial

Izenda Reports is licensed on a "per user" or "per server" basis. Please complete this form to receive a price quote.

All fields are required.

The live demo demonstrates Izenda reports with the Northwind Sample database. To login, please register below.

All fields are required.

Please register to try Izenda reports on your data today.

All fields are required.

How do I dynamically create an export?

Expand / Collapse
 

How do I dynamically create an export?


This code sample allows reports to be dynamically exported by the chosen method (csv here) without user interaction.
using System;
using System.IO;
using System.Xml;
using Izenda.AdHoc;


System.Xml.XmlTextReader tr = new System.Xml.XmlTextReader(reportName);

Izenda.AdHoc.ReportSet rs;
rs = Izenda.AdHoc.ReportSet.InitializeNew();
rs.ReadXml(tr);

Izenda.AdHoc.CsvReportOutputGenerator exp = new Izenda.AdHoc.CsvReportOutputGenerator();
byte[] buf = exp.GenerateOutput(rs).Content;
try
{
System.IO.FileStream fs = System.IO.File.Create(Izenda.AdHoc.AdHocSettings.ReportsPath + "\\output.csv");//this is just a test location
fs.Write(buf, 0, buf.Length);
fs.Close();
}
catch
{
}


 

In case you want to create a class which does this, here is an example:

using System;
using System.IO;
using System.Xml;
using Izenda.AdHoc;

namespace XLSGenerator
{
  class ReportGenerator
  {
      public int Start(string fromFile, string toFile)
      {
          XmlTextReader reader;
          FileStream fs;
          ReportSet reportSet;
          try
          {
              reader = new XmlTextReader(fromFile);
          }
          catch(Exception e)
          {
              return 1;
          }

          try
          {
              fs = new FileStream(toFile, FileMode.Create);
          }
          catch(Exception e)
          {
              return 2;
          }

        
          AdHocSettings.LicenseKey = "LicenseKey";
          AdHocContext.Driver.ConnectionString = "ConnectionString";

          reportSet = ReportSet.InitializeNew();
          reportSet.ReadXml(reader);
                    HtmlOutputGenerator outputGenerator = new HtmlOutputGenerator("xls");
          byte[] buff = outputGenerator.GenerateOutput(reportSet).Content;
          fs.Write(buff, 0, buff.Length);
          fs.Close();
          return 0;
      }
  }
} 



Details
Type: FAQ
Options