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;
}
}
}