/// <summary> /// Report Initialization method that is triggered when report begin processed. /// </summary> /// <param name="reportOptions">The ReportViewer options.</param> public void OnInitReportOptions(ReportViewerOptions reportOptions) { //throw new NotImplementedException(); // Add RDL Server and database credentials here // Report Server string user = LibraryHelper.AppSettings <string>("Report.RDLUser"); string password = LibraryHelper.AppSettings <string>("Report.RDLPassword"); reportOptions.ReportModel.ReportServerCredential = new System.Net.NetworkCredential(user, password); // Data Source string connectionName = "Chinook"; string[] userPassword = AdoNetHelper.GetUserPassword(connectionName); DataSourceCredentials dataSourceCredentials = new DataSourceCredentials(connectionName, userPassword[0], userPassword[1]); reportOptions.ReportModel.DataSourceCredentials.Add(dataSourceCredentials); }
public static bool ExportRDL(ZOperationResult operationResult, ref string exportPath, string exportFormat, string reportDirectory, string reportName, IDictionary <string, string> reportParameters) { try { ReportWriter reportWriter = new ReportWriter(); reportWriter.ReportPath = "/" + MultiTenantHelper.Tenant.Name + (String.IsNullOrEmpty(reportDirectory) ? "" : "/" + reportDirectory) + "/" + reportName; reportWriter.ReportProcessingMode = ProcessingMode.Remote; // Report Credentials string user = ConfigurationHelper.AppSettings <string>("Report.RDL.User"); string password = ConfigurationHelper.AppSettings <string>("Report.RDL.Password"); reportWriter.ReportServerCredential = new System.Net.NetworkCredential(user, password); reportWriter.ReportServerUrl = ConfigurationHelper.AppSettings <string>("Report.RDL.Url"); // Data Source Credentials string connection = reportDirectory; string[] userPassword = AdoNetHelper.GetUserPassword(connection); DataSourceCredentials dataSourceCredentials = new DataSourceCredentials(connection, userPassword[0], userPassword[1]); reportWriter.SetDataSourceCredentials(new DataSourceCredentials[] { dataSourceCredentials }); // Parameter(s) IList <ReportParameter> reportWriterParameters = new List <ReportParameter>(); // Syncfusion.Reports.EJ.ReportParameter foreach (KeyValuePair <string, string> pair in reportParameters) { ReportParameter reportParameter = new ReportParameter(); reportParameter.Name = pair.Key; reportParameter.Values.Add(pair.Value); reportWriterParameters.Add(reportParameter); } reportWriter.SetParameters(reportWriterParameters); // Data Source(s) & DataSet(s) // Export string fileExtension = ".pdf"; WriterFormat writerFormat = WriterFormat.PDF; switch (exportFormat.ToLower()) { case "doc": fileExtension = ".doc"; writerFormat = WriterFormat.Word; break; case "xls": fileExtension = ".xls"; writerFormat = WriterFormat.Excel; break; } exportPath = exportPath.Trim() + fileExtension; FileStream fileStream = new FileStream(exportPath, FileMode.Create); reportWriter.Save(fileStream, writerFormat); fileStream.Close(); operationResult.StatusMessage = exportPath; } catch (Exception exception) { operationResult.ParseException(exception); } return(operationResult.Ok); }