Sie sind auf Seite 1von 2

This article explains how to download a report automatically and save in a local folder.

I've taken the example of sales invoice, the following code will download the sales order
invoice automatically and save the PDF file in the specified path.

SrsReportRunController controller = new SrsReportRunController();


SalesInvoiceContract rdpContract = new SalesInvoiceContract();
SRSPrintDestinationSettings settings;
System.Byte[] reportBytes = new System.Byte[0]();
SRSProxy srsProxy;
SRSReportRunService srsReportRunService = new SrsReportRunService();
Microsoft.Dynamics.AX.Framework.Reporting.Shared.ReportingService.Parameter
Value[] parameterValueArray;
Map reportParametersMap;
SRSReportExecutionInfo executionInfo = new SRSReportExecutionInfo();
;

if ( _custInvoiceJour)
{
if (!WinAPI::pathExists("C:\\Temp\\Invoices\\"))
WinAPI::createDirectoryPath("C:\\Temp\\Invoices\\");

filename
=strfmt('C:\\Temp\\Invoices\\%1%2',_custInvoiceJour.InvoiceId,".pdf");

controller.parmReportName(ssrsReportStr(SalesInvoic, ReportTH));
controller.parmShowDialog(false);

// Explicitly provide all required parameters


rdpContract.parmRecordId(_custInvoiceJour.RecId);
controller.parmReportContract().parmRdpContract(rdpContract);

// Change print settings as needed


settings = controller.parmReportContract().parmPrintSettings();
settings.printMediumType(SRSPrintMediumType::File);
settings.fileFormat(SRSReportFileFormat::PDF);
settings.overwriteFile(true);
settings.fileName(filename);
controller.parmReportContract().parmReportServerConfig(
SRSConfiguration::getDefaultServerConfiguration());
controller.parmReportContract().parmReportExecutionInfo(executionInfo);
srsReportRunService.getReportDataContract(
controller.parmreportcontract().parmReportName());
srsReportRunService.preRunReport(controller.parmreportcontract());
reportParametersMap
= srsReportRunService.createParamMapFromContract(controller.parmReportContract(
));
parameterValueArray =
SrsReportRunUtil::getParameterValueArray(reportParametersMap);
srsProxy =
SRSProxy::constructWithConfiguration(controller.parmReportContract().parmReportSe
rverConfig());
// Actual rendering to byte array
reportBytes =
srsproxy.renderReportToByteArray(controller.parmreportcontract().parmreportpath(),
parameterValueArray,
settings.fileFormat(),
settings.deviceinfo());

if (reportBytes)
{
System.IO.Stream stream = new
System.IO.MemoryStream(reportBytes);
var fileStream = new System.IO.FileStream(filename,
System.IO.FileMode::Create, System.IO.FileAccess::ReadWrite);
stream.CopyTo(fileStream);

Das könnte Ihnen auch gefallen