0373f2b5ea411a98df2ddd8a028ab035cd245f44
FAQ/SaveReportSet.md
| ... | ... | @@ -0,0 +1,72 @@ |
| 1 | +#SaveReportSet() |
|
| 2 | + |
|
| 3 | +[[_TOC_]] |
|
| 4 | + |
|
| 5 | +##About |
|
| 6 | + |
|
| 7 | +This method is used to define how your reports are stored. By default, using [[DatabaseAdHocConfig|http://wiki.izenda.us/FAQ/Storing-Reports#Database-Mode]] will save your reports in the [[SavedReportsTable|http://wiki.izenda.us/API/CodeSamples/SavedReportsTable]] and using [[FileSystemAdHocConfig|http://wiki.izenda.us/FAQ/Storing-Reports#File-System-Mode]] will save them to the Reports folder on your server's file system. You can redefine that behavior by overriding this method in your [[CustomAdHocConfig|http://wiki.izenda.us/API/AdHocConfig]] class. |
|
| 8 | + |
|
| 9 | +##Sample C Methods |
|
| 10 | + |
|
| 11 | +###DatabaseAdHocConfig |
|
| 12 | + |
|
| 13 | +```csharp |
|
| 14 | +public override void SaveReportSet(string reportName, ReportSet reportSet) { |
|
| 15 | + // BEGIN Database Mode Code Sample |
|
| 16 | + string SavedReportsTable = AdHocSettings.SavedReportsTable; |
|
| 17 | + string sql = string.Format(@" |
|
| 18 | +IF (EXISTS (SELECT Name FROM {2} WHERE Name = '{0}')) |
|
| 19 | +BEGIN |
|
| 20 | + UPDATE {2} SET Xml = '{1}' WHERE Name = '{0}' |
|
| 21 | +END |
|
| 22 | +ELSE |
|
| 23 | +BEGIN |
|
| 24 | + INSERT INTO {2} (Name, Xml) VALUES ('{0}', '{1}') |
|
| 25 | +END", |
|
| 26 | + reportName.Trim(), |
|
| 27 | + reportSet.WriteXml(), |
|
| 28 | + SavedReportsTable); |
|
| 29 | + |
|
| 30 | + System.Data.IDbCommand command = Izenda.AdHoc.AdHocContext.Driver.CreateCommand(sql); |
|
| 31 | + try { |
|
| 32 | + command.ExecuteNonQuery(); |
|
| 33 | + } |
|
| 34 | + finally { |
|
| 35 | + if (command.Connection.State == System.Data.ConnectionState.Open) |
|
| 36 | + command.Connection.Close(); |
|
| 37 | + } |
|
| 38 | + // END Database Mode Code Sample |
|
| 39 | +} |
|
| 40 | +``` |
|
| 41 | + |
|
| 42 | +###FileSystemAdHocConfig |
|
| 43 | + |
|
| 44 | +``` |
|
| 45 | +public override void SaveReportSet(string reportName, Izenda.AdHoc.ReportSet reportSet) { |
|
| 46 | + // BEGIN Filesystem Mode Code Sample |
|
| 47 | + DirectoryInfo dir = new DirectoryInfo(ReportPath); |
|
| 48 | + string message = string.Format("{0} does not exist, Set Izenda.AdHoc.AdHocSettings.ReportsPath to the proper path and give full permission to the {1} for that folder." |
|
| 49 | + , dir.FullName |
|
| 50 | + , Thread.CurrentPrincipal.Identity.Name); |
|
| 51 | + if (!dir.Exists) |
|
| 52 | + throw new DirectoryNotFoundException(message); |
|
| 53 | + |
|
| 54 | + string fileName = Path.Combine(ReportPath, reportName + ".xml"); |
|
| 55 | + try { |
|
| 56 | + FileInfo file = new FileInfo(fileName); |
|
| 57 | + if (!file.Directory.Exists) |
|
| 58 | + file.Directory.Create(); |
|
| 59 | + StreamWriter writer = file.CreateText(); |
|
| 60 | + string xml = reportSet.WriteXml(); |
|
| 61 | + writer.Write(xml); |
|
| 62 | + writer.Close(); |
|
| 63 | + } |
|
| 64 | + catch (UnauthorizedAccessException e) { |
|
| 65 | + throw new Exception("Make make sure 'NETWORK SERVICE' or 'ASPNET' has full permission to the Reports folder.\n" + e.Message); |
|
| 66 | + } |
|
| 67 | + catch (SecurityException e) { |
|
| 68 | + throw new Exception("Make make sure 'NETWORK SERVICE' or 'ASPNET' has full permission to the Reports folder.\n" + e.Message); |
|
| 69 | + } |
|
| 70 | + // END Filesystem Mode Code Sample |
|
| 71 | +} |
|
| 72 | +``` |
|
| ... | ... | \ No newline at end of file |