#ArchiveReportOutput()
##About
If you want to archive report output every time reports are executed, you could use the ArchiveReportOutput method. By overriding this method, you could easily archive any report(save to a file, output through FTP, send through email, etc.) This method runs every time after report execution, so you may need to be selective about when you actually archive a report. In the example below, we will only archive reports made by a particular user.
##Global.asax (C♯)
//main class: inherits DatabaseAdHocConfig or FileSystemAdHocConfig
public class CustomAdHocConfig : Izenda.AdHoc.DatabaseAdHocConfig
{
public override void ArchiveReportOutput(ReportSet reportSet, string[] emails, string extension, byte[] data)
{
// Use archiving only for scheduler
if (!AdHocContext.SchedulerExecuting)
return;
// Check for permissions
if (reportSet.Owner != "test@test.com")
return;
// Look up report archive directory
string reportPath = savePath + LookUpTenantID(reportSet.Owner) + "\\";
if (!Directory.Exists(reportPath))
Directory.CreateDirectory(reportPath);
// Save report output to the archive
using (FileStream sw = new FileStream(reportPath + reportSet.ReportName + "." + extension, FileMode.Create))
using (BinaryWriter bw = new BinaryWriter(sw))
bw.Write(data);
}
}
##Global.asax (VB.NET)
'main class: inherits DatabaseAdHocConfig or FileSystemAdHocConfig
Public Class CustomAdHocConfig
Inherits Izenda.AdHoc.DatabaseAdHocConfig
Public Overrides Sub ArchiveReportOutput(ByVal reportSet As ReportSet, ByVal emails() As String, ByVal extension As String, ByVal data() As Byte)
' Use archiving only for scheduler
If Not AdHocContext.SchedulerExecuting Then Return
' Check for permissions
If reportSet.Owner != "test@test.com" Then Return
' Look up report archive directory
Dim reportPath As String = savePath + LookUpTenantID(reportSet.Owner) + "\\"
If Not Directory.Exists(reportPath) Then Directory.CreateDirectory(reportPath)
' Save report output to the archive
Using sw As New FileStream(reportPath + reportSet.Name + "." + extension, FileMode.Create)
Using bw As New BinaryWriter(sw)
bw.Write(data)
End Using
End Using
End Sub
End Class
_Note: You might like to run auto-archiving only when the scheduler executes. Using SchedulerExecuting, you could know if this output is generated by the scheduler.
