public static List <ReportParameterInfo> getReportParameters(ReportViewerModel model)
        {
            var contentData       = new ReportExportResult();
            var definedParameters = ReportServiceHelpers.GetReportParameters(model, true);

            contentData.SetParameters(definedParameters, model.Parameters);
            return(contentData.Parameters);
        }
        /// <summary>
        /// Searches a specific report for your provided searchText and returns the page that it located the text on.
        /// </summary>
        /// <param name="model"></param>
        /// <param name="searchText">The text that you want to search in the report</param>
        /// <param name="startPage">Starting page for the search to begin from.</param>
        /// <returns></returns>
        public static int?FindStringInReport(ReportViewerModel model, string searchText, int?startPage = 0)
        {
            var url = model.ServerUrl + ((model.ServerUrl.ToSafeString().EndsWith("/")) ? "" : "/") + "ReportExecution2005.asmx";

            var basicHttpBinding = _initializeHttpBinding(url, model);
            var service          = new ReportServiceExecution.ReportExecutionServiceSoapClient(basicHttpBinding, new System.ServiceModel.EndpointAddress(url));

            service.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
            service.ClientCredentials.Windows.ClientCredential          = (System.Net.NetworkCredential)(model.Credentials ?? System.Net.CredentialCache.DefaultCredentials);

            var cred = model.Credentials?.GetCredential(new Uri(url), "Basic");

            service.ClientCredentials.UserName.UserName = cred?.UserName;
            service.ClientCredentials.UserName.Password = cred?.Password;

            var definedReportParameters = GetReportParameters(model, true);

            if (!startPage.HasValue || startPage == 0)
            {
                startPage = 1;
            }

            var exportResult = new ReportExportResult();

            exportResult.CurrentPage = startPage.ToInt32();
            exportResult.SetParameters(definedReportParameters, model.Parameters);

            var format         = "HTML4.0";
            var outputFormat   = $"<OutputFormat>{format}</OutputFormat>";
            var encodingFormat = $"<Encoding>{model.Encoding.EncodingName}</Encoding>";
            var htmlFragment   = ((format.ToUpper() == "HTML4.0" && model.UseCustomReportImagePath == false && model.ViewMode == ReportViewModes.View) ? "<HTMLFragment>true</HTMLFragment>" : "");
            var deviceInfo     = $"<DeviceInfo>{outputFormat}{encodingFormat}<Toolbar>False</Toolbar>{htmlFragment}</DeviceInfo>";

            if (model.ViewMode == ReportViewModes.View && startPage.HasValue && startPage > 0)
            {
                deviceInfo = $"<DeviceInfo>{outputFormat}<Toolbar>False</Toolbar>{htmlFragment}<Section>{startPage}</Section></DeviceInfo>";
            }

            var reportParameters = new List <ReportServiceExecution.ParameterValue>();

            foreach (var parameter in exportResult.Parameters)
            {
                bool addedParameter = false;
                foreach (var value in parameter.SelectedValues)
                {
                    var reportParameter = new ReportServiceExecution.ParameterValue();
                    reportParameter.Name  = parameter.Name;
                    reportParameter.Value = value;
                    reportParameters.Add(reportParameter);

                    addedParameter = true;
                }

                if (!addedParameter)
                {
                    var reportParameter = new ReportServiceExecution.ParameterValue();
                    reportParameter.Name = parameter.Name;
                    reportParameters.Add(reportParameter);
                }
            }

            var executionHeader = new ReportServiceExecution.ExecutionHeader();

            ReportServiceExecution.ExecutionInfo executionInfo = null;
            string extension = null;
            string encoding  = null;
            string mimeType  = null;

            string[] streamIDs = null;
            ReportServiceExecution.Warning[] warnings = null;

            try
            {
                string historyID = null;
                executionInfo = service.LoadReportAsync(model.ReportPath, historyID).Result;
                executionHeader.ExecutionID = executionInfo.ExecutionID;
                var executionParameterResult = service.SetReportParameters(executionInfo.ExecutionID, reportParameters.ToArray(), "en-us").Result;

                var renderRequest = new ReportServiceExecution.Render2Request(format, deviceInfo, ReportServiceExecution.PageCountMode.Actual);
                var result        = service.Render2(executionInfo.ExecutionID, renderRequest).Result;

                extension = result.Extension;
                mimeType  = result.MimeType;
                encoding  = result.Encoding;
                warnings  = result.Warnings;
                streamIDs = result.StreamIds;

                executionInfo = service.GetExecutionInfo(executionHeader.ExecutionID).Result;

                return(service.FindString(executionInfo.ExecutionID, startPage.ToInt32(), executionInfo.NumPages, searchText).Result);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return(0);
        }
        public static string ParametersToHtmlString(System.Collections.Generic.List <ReportParameterInfo> parameters, ReportViewerModel model)
        {
            StringBuilder sb = new StringBuilder();

            if (parameters == null)
            {
                var contentData       = new ReportExportResult();
                var definedParameters = ReportServiceHelpers.GetReportParameters(model, true);
                contentData.SetParameters(definedParameters, model.Parameters);
                parameters = contentData.Parameters;
            }

            //Parameters start
            foreach (var reportParameter in parameters)
            {
                sb.AppendLine("					<div class='Parameter col-md-6 col-sm-12'>");
                if (reportParameter.PromptUser || model.ShowHiddenParameters)
                {
                    sb.AppendLine($"						<div class='col-sm-4'><label for='{reportParameter.Name}'>{reportParameter.Prompt}</label></div>");

                    sb.AppendLine("							<div class='col-sm-8'>");
                    if (reportParameter.ValidValues != null && reportParameter.ValidValues.Any())
                    {
                        sb.AppendLine($"						<select id='{reportParameter.Name}' name='{reportParameter.Name}' class='form-control' {(reportParameter.MultiValue == true ? "multiple='multiple'" : "")}>");
                        foreach (var value in reportParameter.ValidValues)
                        {
                            sb.AppendLine($"							<option value='{value.Value}' {(reportParameter.SelectedValues.Contains(value.Value) ? "selected='selected'" : "")}>{value.Label}</option>");
                        }
                        sb.AppendLine($"						</select>");
                    }
                    else
                    {
                        var selectedValue = reportParameter.SelectedValues.FirstOrDefault();

                        if (reportParameter.Type == ReportService.ParameterTypeEnum.Boolean)
                        {
                            sb.AppendLine($"						<input type='checkbox' id='{reportParameter.Name}' name='{reportParameter.Name}' class='form-control' {(selectedValue.ToBoolean() ? "checked='checked'" : "")} />");
                        }
                        else if (reportParameter.Type == ReportService.ParameterTypeEnum.DateTime)
                        {
                            sb.AppendLine($"						<input type='datetime' id='{reportParameter.Name}' name='{reportParameter.Name}' class='form-control' value='{selectedValue}' />");
                        }
                        else
                        {
                            sb.AppendLine($"						<input type='text' id='{reportParameter.Name}' name='{reportParameter.Name}' class='form-control' value='{selectedValue}' />");
                        }
                    }

                    sb.AppendLine("							</div>");
                }
                else
                {
                    if (reportParameter.SelectedValues != null && reportParameter.SelectedValues.Any())
                    {
                        var values = reportParameter.SelectedValues.Where(x => x != null).Select(x => x).ToArray();
                        sb.AppendLine($"			<input type='hidden' id='{reportParameter.Name}' name='{reportParameter.Name}' value='{String.Join(",", values)}' />");
                    }
                }

                sb.AppendLine($"			<input type='hidden' id='ReportViewerEnablePaging' name='ReportViewerEnablePaging' value='{model.EnablePaging}' />");

                sb.AppendLine("					</div>");
            }

            return(sb.ToString());
        }
        public static ReportExportResult ExportReportToFormat(ReportViewerModel model, string format, int?startPage = 0, int?endPage = 0)
        {
            var service = new ReportServiceExecution.ReportExecutionService
            {
                Url =
                    model.ServerUrl + ((model.ServerUrl.ToSafeString().EndsWith("/")) ? "" : "/") + "ReportExecution2005.asmx",
                Credentials = model.Credentials ?? System.Net.CredentialCache.DefaultCredentials
            };

            var definedReportParameters = GetReportParameters(model, true);

            var exportResult = new ReportExportResult {
                CurrentPage = (startPage.ToInt32() <= 0 ? 1 : startPage.ToInt32())
            };

            exportResult.SetParameters(definedReportParameters, model.Parameters);

            if (startPage == 0)
            {
                startPage = 1;
            }

            if (endPage == 0)
            {
                endPage = startPage;
            }

            var outputFormat = $"<OutputFormat>{format}</OutputFormat>";
            var htmlFragment = ((format.ToUpper() == "HTML4.0" && model.UseCustomReportImagePath == false && model.ViewMode == ReportViewModes.View) ? "<HTMLFragment>true</HTMLFragment>" : "");
            var deviceInfo   = $"<DeviceInfo>{outputFormat}<Toolbar>False</Toolbar>{htmlFragment}</DeviceInfo>";

            if (model.ViewMode == ReportViewModes.View && startPage.HasValue && startPage > 0)
            {
                deviceInfo = $"<DeviceInfo>{outputFormat}<Toolbar>False</Toolbar>{htmlFragment}<Section>{startPage}</Section></DeviceInfo>";
            }

            var reportParameters = new List <ReportServiceExecution.ParameterValue>();

            foreach (var parameter in exportResult.Parameters)
            {
                bool addedParameter = false;
                foreach (var value in parameter.SelectedValues)
                {
                    var reportParameter = new ReportServiceExecution.ParameterValue
                    {
                        Name  = parameter.Name,
                        Value = value
                    };
                    reportParameters.Add(reportParameter);

                    addedParameter = true;
                }

                if (!addedParameter)
                {
                    var reportParameter = new ReportServiceExecution.ParameterValue {
                        Name = parameter.Name
                    };
                    reportParameters.Add(reportParameter);
                }
            }

            var executionHeader = new ReportServiceExecution.ExecutionHeader();

            service.ExecutionHeaderValue = executionHeader;

            ReportServiceExecution.ExecutionInfo executionInfo = null;
            string mimeType = null;

            string[] streamIDs = null;
            ReportServiceExecution.Warning[] warnings = null;

            try
            {
                string historyID = null;
                executionInfo = service.LoadReport(model.ReportPath, historyID);
                service.SetExecutionParameters(reportParameters.ToArray(), "en-us");

                string extension;
                string encoding;
                var    result = service.Render2(format, deviceInfo, ReportServiceExecution.PageCountMode.Actual, out extension, out mimeType, out encoding, out warnings, out streamIDs);

                executionInfo = service.GetExecutionInfo();

                exportResult.ReportData = result;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            exportResult.ExecutionInfo = executionInfo;
            exportResult.Format        = format;
            exportResult.MimeType      = mimeType;
            exportResult.StreamIDs     = streamIDs?.ToList() ?? new List <string>();
            exportResult.Warnings      = warnings?.ToList() ?? new List <ReportServiceExecution.Warning>();

            if (executionInfo != null)
            {
                exportResult.TotalPages = executionInfo.NumPages;
            }

            return(exportResult);
        }
        /// <summary>
        /// Searches a specific report for your provided searchText and returns the page that it located the text on.
        /// </summary>
        /// <param name="model"></param>
        /// <param name="searchText">The text that you want to search in the report</param>
        /// <param name="startPage">Starting page for the search to begin from.</param>
        /// <returns></returns>
        public static int?FindStringInReport(ReportViewerModel model, string searchText, int?startPage = 0)
        {
            var service = new ReportServiceExecution.ReportExecutionService
            {
                Url =
                    model.ServerUrl + ((model.ServerUrl.ToSafeString().EndsWith("/")) ? "" : "/") +
                    "ReportExecution2005.asmx",
                Credentials = model.Credentials ?? System.Net.CredentialCache.DefaultCredentials
            };

            var definedReportParameters = GetReportParameters(model, true);

            if (!startPage.HasValue || startPage == 0)
            {
                startPage = 1;
            }

            var exportResult = new ReportExportResult {
                CurrentPage = startPage.ToInt32()
            };

            exportResult.SetParameters(definedReportParameters, model.Parameters);

            var deviceInfo = $"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";

            var reportParameters = new List <ReportServiceExecution.ParameterValue>();

            foreach (var parameter in exportResult.Parameters)
            {
                bool addedParameter = false;
                foreach (var value in parameter.SelectedValues)
                {
                    var reportParameter = new ReportServiceExecution.ParameterValue
                    {
                        Name  = parameter.Name,
                        Value = value
                    };
                    reportParameters.Add(reportParameter);

                    addedParameter = true;
                }

                if (!addedParameter)
                {
                    var reportParameter = new ReportServiceExecution.ParameterValue {
                        Name = parameter.Name
                    };
                    reportParameters.Add(reportParameter);
                }
            }

            var executionHeader = new ReportServiceExecution.ExecutionHeader();

            service.ExecutionHeaderValue = executionHeader;

            try
            {
                string historyID     = null;
                var    executionInfo = service.LoadReport(model.ReportPath, historyID);
                service.SetExecutionParameters(reportParameters.ToArray(), "en-us");

                return(service.FindString(startPage.ToInt32(), executionInfo.NumPages, searchText));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return(0);
        }
Exemple #6
0
        public static ReportExportResult ExportReportToFormat(ReportViewerModel model, string format, int?startPage = 0, int?endPage = 0)
        {
            var service = _initializeReportExecutionService(model);
            var definedReportParameters = GetReportParameters(model, true);

            var exportResult = new ReportExportResult();

            exportResult.CurrentPage = (startPage.ToInt32() <= 0 ? 1 : startPage.ToInt32());
            exportResult.SetParameters(definedReportParameters, model.Parameters);

            if (startPage == 0)
            {
                startPage = 1;
            }

            if (endPage == 0)
            {
                endPage = startPage;
            }

            var outputFormat   = $"<OutputFormat>{format}</OutputFormat>";
            var encodingFormat = $"<Encoding>{model.Encoding.EncodingName}</Encoding>";
            var htmlFragment   = ((format.ToUpper() == "HTML4.0" && model.UseCustomReportImagePath == false && model.ViewMode == ReportViewModes.View) ? "<HTMLFragment>true</HTMLFragment>" : "");
            var deviceInfo     = $"<DeviceInfo>{outputFormat}<Toolbar>False</Toolbar>{htmlFragment}</DeviceInfo>";

            if (model.ViewMode == ReportViewModes.View && startPage.HasValue && startPage > 0)
            {
                if (model.EnablePaging)
                {
                    deviceInfo = $"<DeviceInfo>{outputFormat}{encodingFormat}<Toolbar>False</Toolbar>{htmlFragment}<Section>{startPage}</Section></DeviceInfo>";
                }
                else
                {
                    deviceInfo = $"<DeviceInfo>{outputFormat}{encodingFormat}<Toolbar>False</Toolbar>{htmlFragment}</DeviceInfo>";
                }
            }

            var reportParameters = new List <ReportServiceExecution.ParameterValue>();

            foreach (var parameter in exportResult.Parameters)
            {
                bool addedParameter = false;
                foreach (var value in parameter.SelectedValues)
                {
                    var reportParameter = new ReportServiceExecution.ParameterValue();
                    reportParameter.Name  = parameter.Name;
                    reportParameter.Value = value;
                    reportParameters.Add(reportParameter);

                    addedParameter = true;
                }

                if (!addedParameter)
                {
                    var reportParameter = new ReportServiceExecution.ParameterValue();
                    reportParameter.Name = parameter.Name;
                    reportParameters.Add(reportParameter);
                }
            }

            var executionHeader = new ReportServiceExecution.ExecutionHeader();

            service.ExecutionHeaderValue = executionHeader;

            ReportServiceExecution.ExecutionInfo executionInfo = null;
            string extension = null;
            string encoding  = null;
            string mimeType  = null;

            string[] streamIDs = null;
            ReportServiceExecution.Warning[] warnings = null;

            try
            {
                string historyID = null;
                executionInfo = service.LoadReport(model.ReportPath, historyID);
                service.SetExecutionParameters(reportParameters.ToArray(), "en-us");

                if (model.EnablePaging)
                {
                    var result = service.Render2(format, deviceInfo, ReportServiceExecution.PageCountMode.Actual, out extension, out mimeType, out encoding, out warnings, out streamIDs);

                    exportResult.ReportData = result;
                }
                else
                {
                    var result = service.Render(format, deviceInfo, out extension, out mimeType, out encoding, out warnings, out streamIDs);

                    exportResult.ReportData = result;
                }

                executionInfo = service.GetExecutionInfo();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            exportResult.ExecutionInfo = executionInfo;
            exportResult.Format        = format;
            exportResult.MimeType      = mimeType;
            exportResult.StreamIDs     = (streamIDs == null ? new List <string>() : streamIDs.ToList());
            exportResult.Warnings      = (warnings == null ? new List <ReportServiceExecution.Warning>() : warnings.ToList());

            if (executionInfo != null)
            {
                exportResult.TotalPages = executionInfo.NumPages;
            }

            return(exportResult);
        }
        public static async Task <ReportExportResult> ExportReportToFormatAsync(ReportViewerModel model, string format, int?startPage = 0, int?endPage = 0)
        {
            var definedReportParameters = await GetReportParametersAsync(model, true);

            var url = model.ServerUrl + ((model.ServerUrl.ToSafeString().EndsWith("/")) ? "" : "/") + "ReportExecution2005.asmx";

            var basicHttpBinding = _initializeHttpBinding(url, model);
            var service          = new ReportServiceExecution.ReportExecutionServiceSoapClient(basicHttpBinding, new System.ServiceModel.EndpointAddress(url));

            service.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
            service.ClientCredentials.Windows.ClientCredential          = (System.Net.NetworkCredential)(model.Credentials ?? System.Net.CredentialCache.DefaultCredentials);

            var exportResult = new ReportExportResult();

            exportResult.CurrentPage = (startPage.ToInt32() <= 0 ? 1 : startPage.ToInt32());
            exportResult.SetParameters(definedReportParameters, model.Parameters);

            if (startPage == 0)
            {
                startPage = 1;
            }

            if (endPage == 0)
            {
                endPage = startPage;
            }

            var outputFormat   = $"<OutputFormat>{format}</OutputFormat>";
            var encodingFormat = $"<Encoding>{model.Encoding.EncodingName}</Encoding>";
            var htmlFragment   = ((format.ToUpper() == "HTML4.0" && model.UseCustomReportImagePath == false && model.ViewMode == ReportViewModes.View) ? "<HTMLFragment>true</HTMLFragment>" : "");
            var deviceInfo     = $"<DeviceInfo>{outputFormat}{encodingFormat}<Toolbar>False</Toolbar>{htmlFragment}</DeviceInfo>";

            if (model.ViewMode == ReportViewModes.View && startPage.HasValue && startPage > 0)
            {
                if (model.EnablePaging)
                {
                    deviceInfo = $"<DeviceInfo>{outputFormat}<Toolbar>False</Toolbar>{htmlFragment}<Section>{startPage}</Section></DeviceInfo>";
                }
                else
                {
                    deviceInfo = $"<DeviceInfo>{outputFormat}<Toolbar>False</Toolbar>{htmlFragment}</DeviceInfo>";
                }
            }

            var reportParameters = new List <ReportServiceExecution.ParameterValue>();

            foreach (var parameter in exportResult.Parameters)
            {
                bool addedParameter = false;
                foreach (var value in parameter.SelectedValues)
                {
                    var reportParameter = new ReportServiceExecution.ParameterValue();
                    reportParameter.Name  = parameter.Name;
                    reportParameter.Value = value;
                    reportParameters.Add(reportParameter);

                    addedParameter = true;
                }

                if (!addedParameter)
                {
                    var reportParameter = new ReportServiceExecution.ParameterValue();
                    reportParameter.Name = parameter.Name;
                    reportParameters.Add(reportParameter);
                }
            }

            var executionHeader   = new ReportServiceExecution.ExecutionHeader();
            var trustedUserHeader = new ReportServiceExecution.TrustedUserHeader();

            ReportServiceExecution.ExecutionInfo executionInfo = null;
            string extension = null;
            string encoding  = null;
            string mimeType  = null;

            string[] streamIDs = null;
            ReportServiceExecution.Warning[] warnings = null;

            try
            {
                string historyID      = null;
                var    taskLoadReport = await service.LoadReportAsync(trustedUserHeader, model.ReportPath, historyID);

                executionInfo = taskLoadReport.executionInfo;
                executionHeader.ExecutionID = executionInfo.ExecutionID;

                ;
                var executionParameterResult = await service.SetExecutionParametersAsync(taskLoadReport.ExecutionHeader, new ReportServiceExecution.TrustedUserHeader(), reportParameters.ToArray(), "en-us");

                if (model.EnablePaging)
                {
                    var renderRequest = new ReportServiceExecution.Render2Request(executionHeader, trustedUserHeader, format, deviceInfo, ReportServiceExecution.PageCountMode.Actual);
                    var result        = await service.Render2Async(executionInfo.ExecutionID, renderRequest);

                    extension = result.Extension;
                    mimeType  = result.MimeType;
                    encoding  = result.Encoding;
                    warnings  = result.Warnings;
                    streamIDs = result.StreamIds;

                    exportResult.ReportData = result.Result;
                }
                else
                {
                    var renderRequest = new ReportServiceExecution.RenderRequest(executionHeader, trustedUserHeader, format, deviceInfo);
                    var result        = await service.RenderAsync(executionInfo.ExecutionID, renderRequest);

                    extension = result.Extension;
                    mimeType  = result.MimeType;
                    encoding  = result.Encoding;
                    warnings  = result.Warnings;
                    streamIDs = result.StreamIds;

                    exportResult.ReportData = result.Result;
                }

                executionInfo = await service.GetExecutionInfoAsync(executionHeader.ExecutionID);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            exportResult.ExecutionInfo = executionInfo;
            exportResult.Format        = format;
            exportResult.MimeType      = mimeType;
            exportResult.StreamIDs     = (streamIDs == null ? new List <string>() : streamIDs.ToList());
            exportResult.Warnings      = (warnings == null ? new List <ReportServiceExecution.Warning>() : warnings.ToList());

            if (executionInfo != null)
            {
                exportResult.TotalPages = executionInfo.NumPages;
            }

            return(exportResult);
        }
        /// <summary>
        /// Searches a specific report for your provided searchText and returns the page that it located the text on.
        /// </summary>
        /// <param name="model"></param>
        /// <param name="searchText">The text that you want to search in the report</param>
        /// <param name="startPage">Starting page for the search to begin from.</param>
        /// <returns></returns>
        public static int?FindStringInReport(ReportViewerModel model, string searchText, int?startPage = 0)
        {
            var url = model.ServerUrl + ((model.ServerUrl.ToSafeString().EndsWith("/")) ? "" : "/") + "ReportExecution2005.asmx";

            var basicHttpBinding = _initializeHttpBinding();
            var service          = new ReportServiceExecution.ReportExecutionServiceSoapClient(basicHttpBinding, new System.ServiceModel.EndpointAddress(url));

            service.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
            service.ClientCredentials.Windows.ClientCredential          = (System.Net.NetworkCredential)(model.Credentials ?? System.Net.CredentialCache.DefaultCredentials);

            var definedReportParameters = GetReportParameters(model, true);

            if (!startPage.HasValue || startPage == 0)
            {
                startPage = 1;
            }

            var exportResult = new ReportExportResult();

            exportResult.CurrentPage = startPage.ToInt32();
            exportResult.SetParameters(definedReportParameters, model.Parameters);

            var deviceInfo = $"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";

            var reportParameters = new List <ReportServiceExecution.ParameterValue>();

            foreach (var parameter in exportResult.Parameters)
            {
                bool addedParameter = false;
                foreach (var value in parameter.SelectedValues)
                {
                    var reportParameter = new ReportServiceExecution.ParameterValue();
                    reportParameter.Name  = parameter.Name;
                    reportParameter.Value = value;
                    reportParameters.Add(reportParameter);

                    addedParameter = true;
                }

                if (!addedParameter)
                {
                    var reportParameter = new ReportServiceExecution.ParameterValue();
                    reportParameter.Name = parameter.Name;
                    reportParameters.Add(reportParameter);
                }
            }

            var executionHeader = new ReportServiceExecution.ExecutionHeader();

            ReportServiceExecution.ExecutionInfo executionInfo = null;

            try
            {
                string historyID = null;
                executionInfo = service.LoadReportAsync(model.ReportPath, historyID).Result;
                executionHeader.ExecutionID = executionInfo.ExecutionID;
                var executionParameterResult = service.SetReportParameters(executionInfo.ExecutionID, reportParameters.ToArray(), "en-us").Result;

                return(service.FindString(executionInfo.ExecutionID, startPage.ToInt32(), executionInfo.NumPages, searchText).Result);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return(0);
        }