Scenario: display report as PDF file in Pivotal Client by pressing Task Pad item.
Client Task (click event handler):
// Get file content from server byte[] fileContent = Globals.SystemClient.ExecuteServerTask("Server Task Name", "GetReportContent", new Type[] { typeof(Id) }, new object[] { recordId }) as byte[]; // Create temp file name string fileName = String.Format("{0}.{1}", Guid.NewGuid(), ".pdf"); string tempFilePath = Path.Combine(System.IO.Path.GetTempPath(), fileName); using (MemoryStream stream = new MemoryStream(fileContent)) { using(FileStream fileStream = new FileStream(tempFilePath, FileMode.Create, System.IO.FileAccess.Write)) { stream.WriteTo(fileStream); fileStream.Flush(); fileStream.Close(); // Open file using windows shell Process.Start(tempFilePath); } }Server Task:
[TaskExecute] public byte[] GetReportContent(Id recordId) { try { SystemReport report = this.SystemServer.GetMetaItem<SystemReport>("Report Name") as SystemReport; ReportRunner reportRunner = this.SystemServer.CreateReportRunner(report); reportRunner.ReportOutputFormat = ReportOutputFormat.Pdf; return reportRunner.Run(ReportFilter.SingleRow, recordId, null); } catch (Exception ex) { throw new PivotalApplicationCoreException(ex.Message, ex); } }
No comments:
Post a Comment