18fe9ff43fd3e51a99976b07b8f6757be3a7f345
FAQ/ArchiveReportOutput.md
| ... | ... | @@ -0,0 +1,67 @@ |
| 1 | +#ArchiveReportOutput() |
|
| 2 | + |
|
| 3 | +[[_TOC_]] |
|
| 4 | + |
|
| 5 | +##About |
|
| 6 | + |
|
| 7 | +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. |
|
| 8 | + |
|
| 9 | +##Global.asax (C♯) |
|
| 10 | + |
|
| 11 | +```csharp |
|
| 12 | +//main class: inherits DatabaseAdHocConfig or FileSystemAdHocConfig |
|
| 13 | +public class CustomAdHocConfig : Izenda.AdHoc.DatabaseAdHocConfig |
|
| 14 | +{ |
|
| 15 | + public override void ArchiveReportOutput(ReportSet reportSet, string[] emails, string extension, byte[] data) |
|
| 16 | + { |
|
| 17 | + // Use archiving only for scheduler |
|
| 18 | + if (!AdHocContext.SchedulerExecuting) |
|
| 19 | + return; |
|
| 20 | + |
|
| 21 | + // Check for permissions |
|
| 22 | + if (reportSet.Owner != "test@test.com") |
|
| 23 | + return; |
|
| 24 | + |
|
| 25 | + // Look up report archive directory |
|
| 26 | + string reportPath = savePath + LookUpTenantID(reportSet.Owner) + "\\"; |
|
| 27 | + if (!Directory.Exists(reportPath)) |
|
| 28 | + Directory.CreateDirectory(reportPath); |
|
| 29 | + |
|
| 30 | + // Save report output to the archive |
|
| 31 | + using (FileStream sw = new FileStream(reportPath reportSet.Name + "." + extension, FileMode.Create)) |
|
| 32 | + using (BinaryWriter bw = new BinaryWriter(sw)) |
|
| 33 | + bw.Write(data); |
|
| 34 | + } |
|
| 35 | +} |
|
| 36 | +``` |
|
| 37 | + |
|
| 38 | +VB.NET |
|
| 39 | + |
|
| 40 | +```visualbasic |
|
| 41 | +'main class: inherits DatabaseAdHocConfig or FileSystemAdHocConfig |
|
| 42 | +Public Class CustomAdHocConfig |
|
| 43 | + Inherits Izenda.AdHoc.DatabaseAdHocConfig |
|
| 44 | + |
|
| 45 | + Public Overrides Sub ArchiveReportOutput(ByVal reportSet As ReportSet, ByVal emails() As String, ByVal extension As String, ByVal data() As Byte) |
|
| 46 | + ' Use archiving only for scheduler |
|
| 47 | + If Not AdHocContext.SchedulerExecuting Then Return |
|
| 48 | + |
|
| 49 | + ' Check for permissions |
|
| 50 | + If reportSet.Owner != "test@test.com" Then Return |
|
| 51 | + |
|
| 52 | + ' Look up report archive directory |
|
| 53 | + Dim reportPath As String = savePath + LookUpTenantID(reportSet.Owner) + "\\" |
|
| 54 | + |
|
| 55 | + If Not Directory.Exists(reportPath) Then Directory.CreateDirectory(reportPath) |
|
| 56 | + |
|
| 57 | + ' Save report output to the archive |
|
| 58 | + Using sw As New FileStream(reportPath + reportSet.Name + "." + extension, FileMode.Create) |
|
| 59 | + Using bw As New BinaryWriter(sw) |
|
| 60 | + bw.Write(data) |
|
| 61 | + End Using |
|
| 62 | + End Using |
|
| 63 | + End Sub |
|
| 64 | +End Class |
|
| 65 | +``` |
|
| 66 | + |
|
| 67 | +_**Note:** You might like to run auto-archiving only when the scheduler executes. Using [[SchedulerExecuting/API/CodeSamples/SchedulerExecuting]], you could know if this output is generated by the scheduler. |
|
| ... | ... | \ No newline at end of file |