Files
lux/TestDevExpress/Services/CustomReportStorageWebExtension.cs
Annamaria Sassi 4b41ed6dde - Gestito ReportDesign
- Importazione ReportDesign in ReportViewer
2026-04-03 12:31:42 +02:00

74 lines
2.8 KiB
C#

using System;
using Microsoft.AspNetCore.Hosting;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.Web.Extensions;
using System.Web;
namespace TestDevExpress.Services
{
public class CustomReportStorageWebExtension:ReportStorageWebExtension
{
public override byte[] GetData(string url)
{
string ReportDirectory = "Reports";
try
{
// Parse the string with the report name and parameter values.
string[] parts = url.Split('?');
string reportName = parts[0];
string parametersQueryString = parts.Length > 1 ? parts[1] : String.Empty;
// Create a report instance.
XtraReport report = null;
if (Directory.EnumerateFiles(ReportDirectory).
Select(Path.GetFileNameWithoutExtension).Contains(reportName))
{
byte[] reportBytes = File.ReadAllBytes(Path.Combine(ReportDirectory, reportName + "repx"));
using (MemoryStream ms = new MemoryStream(reportBytes))
report = XtraReport.FromStream(ms);
}
if (report != null)
{
// Apply the parameter values to the report.
var parameters = HttpUtility.ParseQueryString(parametersQueryString);
foreach (string parameterName in parameters.AllKeys)
{
report.Parameters[parameterName].Value = Convert.ChangeType(
parameters.Get(parameterName), report.Parameters[parameterName].Type);
}
// Disable the Visible property for all report parameters
// to hide the Parameters Panel in the viewer.
foreach (var parameter in report.Parameters)
{
parameter.Visible = false;
}
// If you do not hide the panel, disable the report's RequestParameters property.
// report.RequestParameters = false;
using (MemoryStream ms = new MemoryStream())
{
report.SaveLayoutToXml(ms);
return ms.ToArray();
}
}
}
catch (Exception ex)
{
throw new DevExpress.XtraReports.Web.ClientControls.FaultException(
"Could not get report data.", ex);
}
throw new DevExpress.XtraReports.Web.ClientControls.FaultException(
string.Format("Could not find report '{0}'.", url));
}
}
}