Izenda Logo


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.) The ArchiveReportOutput method is called when any type of export (except HTML) or scheduler runs. This method is called only when the process of executing the report is associated with the file creation process (such as exports to PDF, Word, Excel, etc.). This method is not called when you simply view reports in the Report Viewer or when you call the scheduler with a non-file content generating type such as Link, Embedded or HTML. There isn't a way to configure this to run in the viewer. 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)
	// Check for permissions
	if (reportSet.Owner != "test@test.com")
	// Look up report archive directory
	string reportPath = savePath + LookUpTenantID(reportSet.Owner) + "\\";
	if (!Directory.Exists(reportPath))
	// Save report output to the archive
	using (FileStream sw = new FileStream(reportPath + reportSet.ReportName + "." + extension, FileMode.Create))
		using (BinaryWriter bw = new BinaryWriter(sw))

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)
                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.