这是使用 Dotnet Framework 3.5。该报告包含许多高分辨率图像。 我需要知道如何正确处置。
// ReportViewer.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
XtraReport report = new XtraReport();
report.LoadLayout(reportsDirectory + "\\" + Request.Params["rptnme"]);
//For backward compatibility
SqlDataSource.DisableCustomQueryValidation = true;
SqlDataSource.AllowCustomSqlQueries = true;
//Allow all scripts to be run via devexpress for backward compatibility
ScriptPermissionManager.GlobalInstance = new ScriptPermissionManager(ExecutionMode.Unrestricted);
if (report.DataSource is SqlDataSource)
{
ParseParams(report);
}
if (report.DataSource != null)
{
report.DataSourceDemanded += report_DataSourceDemanded;
((SqlDataSource)report.DataSource).ConfigureDataConnection += new ConfigureDataConnectionEventHandler(devReports_Default_ConfigureDataConnection);
}
SubReports(report);
if (Request.Params.Count > 0)
{
if (Request.Params["DisplayName"] != null)
{
report.DisplayName = Request.Params["DisplayName"];
}
}
if (Request.Params["exptyp"] == "pdf" || Request.Params["exptyp"] == "ALL")
{
// Specify export options.
PdfExportOptions pdfExportOptions = new PdfExportOptions()
{
PdfACompatibility = PdfACompatibility.PdfA1b
};
}
DocViewer1.OpenReport(report);
}
// ReportViewer.aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<dx:ASPxWebDocumentViewer ID="DocViewer1" runat="server"
ToolbarMode="Ribbon" DocumentViewerInternal="">
</dx:ASPxWebDocumentViewer>
</div>
</form>
</body>
</html>
此代码是 ASP.NET Web 窗体页面的一部分,用于使用 DevExpress 的报告工具加载和显示报告。以下是 Page_Load 方法的详细说明:
处理报告后,我们将自动处理所有包含的图像。然而,当涉及 ASPxWebDocumentViewer 时,情况要复杂得多。网页的生命周期比预览的报表文档的生命周期短得多。由于我们不想在每次导出或在页面之间导航时重新创建整个文档,因此我们需要将其保存在某个地方。每次预览报告时(例如,通过刷新浏览器页面),您都会获得一份新的文档副本(除非您明确执行此操作,否则不会自动删除前一个文档副本)。这就是为什么您会看到内存使用量不断增加。这可能看起来像内存泄漏,但事实并非如此。此外,我们试图在缓存方面变得聪明:我们没有一个,而是两个存储(内存中和持久)。持久存储还用于在 Web Farm 环境中跨服务器共享文档。检查这些帮助主题,如果您有任何后续问题,请告诉我: 文档查看器生命周期 文档查看器缓存管理。
注意。如果您的文档(图像)非常大并且您希望直接控制报告的生命周期,我建议测试我们的 PdfStreamingExporter。该中介器是专门为大型报告创建的,其中页面一旦准备好就被写入。虽然此替代方案意味着不需要 ASPxWebDocumentViewer,但您仍然可以使用浏览器的内置 PDF 查看器来可视化结果。
问候, 雅罗斯拉夫 DevExpress 支持