protected override void OnGet(HttpRequestEventArgs ev) { WebReport webReport = new WebReport(); webReport.Width = 1000; webReport.Height = 600; webReport.ToolbarIconsStyle = ToolbarIconsStyle.Black; webReport.ToolbarIconsStyle = ToolbarIconsStyle.Black; webReport.PrintInBrowser = true; webReport.PrintInPdf = true; webReport.ShowExports = true; webReport.ShowPrint = true; webReport.SinglePage = true; webReport.Report.Load(@"G:\GitDev\RPC\src\Sample\UcAsp.RPC.Server.Test\bin\Debug\wwwroot\report\temp\Report.frx"); webReport.DesignerPath = @"G:\GitDev\RPC\src\Sample\UcAsp.RPC.Server.Test\bin\Debug\wwwroot\WebReportDesigner/index.html"; webReport.DesignReport = true; webReport.DesignScriptCode = true; webReport.DesignerSavePath = @"G:\GitDev\RPC\src\Sample\UcAsp.RPC.Server.Test\bin\Debug\wwwroot\Theme\content\report\temp\"; webReport.DesignerSaveCallBack = @"G:\GitDev\RPC\src\Sample\UcAsp.RPC.Server.Test\bin\Debug\wwwroot\Report\Manager\SaveDesignedReport"; webReport.ID = "1"; string html = webReport.GetHtml(); ev.Response.WriteContent(Encoding.UTF8.GetBytes(html)); }
public static string GetPreviewHtml(HttpContext context, string connectionString, string dbType, string query, string id) { string html = ""; try { WebReport webReport = GetPreview(context, connectionString, dbType, query, id); html = webReport.GetHtml().ToHtmlString(); } catch (Exception ex) { Log.Error(ex); } return(html); }
// Gets Report by ID with query public HttpResponseMessage GetReportById(int id, [FromUri] ReportQuery query) { // Find the report Reports reportItem = reportItems.FirstOrDefault((p) => p.Id == id); if (reportItem != null) { string reportPath = HostingEnvironment.MapPath("~/App_Data/" + reportItem.ReportName); string dataPath = HostingEnvironment.MapPath("~/App_Data/nwind-employees.xml"); MemoryStream stream = new MemoryStream(); try { using (DataSet dataSet = new DataSet()) { dataSet.ReadXml(dataPath); Config.WebMode = true; using (Report report = new Report()) { report.Load(reportPath); report.RegisterData(dataSet, "NorthWind"); if (query.Parameter != null) { report.SetParameterValue("Parameter", query.Parameter); } // Two prepare Phases for eliminate any report dialogs report.PreparePhase1(); report.PreparePhase2(); if (query.Format == "pdf") { PDFExport pdf = new PDFExport(); report.Export(pdf, stream); } else if (query.Format == "html") { using (HTMLExport html = new HTMLExport()) { html.SinglePage = true; html.Navigator = false; html.EmbedPictures = true; report.Export(html, stream); } } else if (query.Format == "png") { using (ImageExport img = new ImageExport()) { img.ImageFormat = ImageExportFormat.Png; img.SeparateFiles = false; img.ResolutionX = 96; img.ResolutionY = 96; report.Export(img, stream); query.Format = "png"; } } else { WebReport webReport = new WebReport(); webReport.Report.Load(reportPath); webReport.Report.RegisterData(dataSet, "NorthWind"); if (query.Parameter != null) { webReport.Report.SetParameterValue("Parameter", query.Parameter); } // inline registration of FastReport javascript webReport.InlineRegistration = true; webReport.Width = Unit.Percentage(100); webReport.Height = Unit.Percentage(100); // get control HtmlString reportHtml = webReport.GetHtml(); byte[] streamArray = Encoding.UTF8.GetBytes(reportHtml.ToString()); stream.Write(streamArray, 0, streamArray.Length); } } } HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent(stream.ToArray()) }; stream.Dispose(); if (query.Format != null) { result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue(query.Inline ? "inline" : "attachment") { FileName = String.Concat(Path.GetFileNameWithoutExtension(reportPath), ".", query.Format) }; } result.Content.Headers.ContentType = query.Format == null ? new MediaTypeHeaderValue("text/html") : new MediaTypeHeaderValue("application/" + query.Format); return(result); } catch { return(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } } else { return(new HttpResponseMessage(HttpStatusCode.NotFound)); } }