private void DeployLinkedReports(List <ReportInfo> reports, string parentReportsLocation, string linkedReportsLocation, int dateTypeValue) { string targetLocation = CreateTargetLocation(linkedReportsLocation); foreach (ReportInfo report in reports) { string newReport = linkedReportsLocation + "/" + report.Name; if (_bgWorker.CancellationPending) { return; } //// Skip this report when deploying linked - it does not have dates //if (report.FileName.Equals("SQLcmReportAlertRules.rdl")) // continue; // See if we should over if (ItemExists(newReport, ItemTypeEnum.LinkedReport)) { if (_drd.OverwriteExisting) { _rs.DeleteItem(newReport); } else { _bgWorker.ReportProgress(1, String.Format("Skipping linked report: {0}...", linkedReportsLocation + "/" + report.Name)); continue; } } // Create the report _bgWorker.ReportProgress(1, String.Format("Deploying linked report: {0}...", linkedReportsLocation + "/" + report.Name)); _rs.CreateLinkedReport(report.Name, targetLocation, parentReportsLocation + "/" + report.Name, null); // Fix the parameters ReportParameter[] parameters = _rs.GetReportParameters(newReport, null, false, null, null); foreach (ReportParameter parameter in parameters) { if (parameter.Name == "dateType") { parameter.DefaultValues[0] = dateTypeValue.ToString(); } else if (parameter.Name == "startDate") { parameter.PromptUser = false; parameter.PromptUserSpecified = true; } else if (parameter.Name == "endDate") { parameter.PromptUser = false; parameter.PromptUserSpecified = true; } } _rs.SetReportParameters(newReport, parameters); } }
private void GetReportParameters() { try { ReportParameter[] parameters; using (ReportingService2005 reportsServerInstance = ((ReportServerProperties)(SourceNode.TreeView.Tag)).ReportsServerInstance) { reportsServerInstance.Credentials = System.Net.CredentialCache.DefaultCredentials; string historyID = null; bool forRendering = true; ParameterValue[] values = null; DataSourceCredentials[] credentials = null; parameters = reportsServerInstance.GetReportParameters ( SourceNode.FullPath.Replace(SourceNode.TreeView.Nodes[0].Text, string.Empty).Replace(@"\", @"/"), historyID, forRendering, values, credentials ); } int ControlCounter = 0; foreach (var parameter in parameters) { Control control = new Label { Name = string.Format("txParamLabel{0}", ControlCounter), Text = string.Format("[{0} - {1}]", parameter.Name, parameter.Type), Visible = true, Height = 120 }; flowLayoutPanel1.Controls.Add(control); control = (parameter.Type != ParameterTypeEnum.Boolean) ? new TextBox() : new CheckBox() as Control; control.Name = string.Format("txDynamicControl{0}", ControlCounter); control.Visible = true; control.Tag = parameter; control.Height = 120; flowLayoutPanel1.Controls.Add(control); ControlCounter++; } } catch (Exception exception) { MessageBox.Show(exception.Message); } }
/// <summary> /// get report parameters /// </summary> private void FillParameter() { Cursor = Cursors.WaitCursor; grdParameters.Rows.Clear(); try { ReportParameter[] parameter = _reportServerProperties2005.GetReportParameters(_reportPath, null, false, null, null); foreach (ReportParameter reportParameter in parameter) { int index = grdParameters.Rows.Add(); DataGridViewRow row = grdParameters.Rows[index]; row.Cells["grdColParams"] = new DataGridViewTextBoxCell { Value = reportParameter.Name }; row.Cells["grdColType"] = new DataGridViewTextBoxCell { Value = reportParameter.Type.ToString() }; row.Cells["grdColNullable"] = new DataGridViewTextBoxCell { Value = reportParameter.Nullable.ToString() }; row.Cells["grdColState"] = new DataGridViewTextBoxCell { Value = reportParameter.State.ToString() }; row.Cells["grdColDefault"] = new DataGridViewTextBoxCell { Value = (reportParameter.DefaultValues != null) ? string.Join(",", (reportParameter.DefaultValues.Where(p => p != null).Select(p => p.ToString()).ToArray())) : string.Empty }; row.Cells["grdColVars"] = LoadComboCellVariables(reportParameter.Type.ToString()); row.Cells["grdColExpression"] = new DataGridViewButtonCell(); } if (_isFirstLoad) { var mappingParams = (MappingParams)_taskHost.Properties[Keys.MAPPING_PARAMS].GetValue(_taskHost); foreach (MappingParam mappingParam in mappingParams) { foreach (DataGridViewRow row in grdParameters.Rows.Cast <DataGridViewRow>().Where(row => row.Cells[0].Value.ToString() == mappingParam.Name)) { ((DataGridViewComboBoxCell)row.Cells[5]).Items.Add(mappingParam.Value); row.Cells[5].Value = mappingParam.Value; } } } _isFirstLoad = false; } catch { } Cursor = Cursors.Arrow; }
public List <List <String> > GetReportParameters(string path) { return(webserviceProxy.GetReportParameters(path, null, false, null, null) .Select(parameter => new List <String> { parameter.Name, parameter.Type.ToString(), parameter.AllowBlank.ToString(), parameter.Nullable.ToString(), parameter.MultiValue.ToString(), parameter.Prompt }) .ToList()); }
protected string Get2005Parameters(string url) { var parameters2005 = srs2005.GetReportParameters(url, null, true, null, null); var builder = new StringBuilder(); foreach (var param in parameters2005) { if (param.Prompt == string.Empty) { AppendParamValue(builder, param.Name, ParamTemplate2005); } } return(builder.ToString()); }
private string RSNOIM(string url, SPWeb web) { parametersSSRS2005 = srs2005.GetReportParameters(url, null, true, null, null); string parameters = ""; foreach (SSRS2005.ReportParameter rp in parametersSSRS2005) { if (rp.Prompt == "") { switch (rp.Name) { case "URL": parameters += "&URL=" + HttpUtility.UrlEncode(web.ServerRelativeUrl); break; case "SiteId": parameters += "&SiteId=" + SPContext.Current.Site.ID; break; case "WebId": parameters += "&WebId=" + SPContext.Current.Web.ID; break; case "UserId": parameters += "&UserId=" + SPContext.Current.Web.CurrentUser.ID; break; case "Username": parameters += "&Username=" + HttpContext.Current.User.Identity.Name; break; } ; } } return(parameters); }
/// <summary> /// Gets the time zone of the Base Transcription Company for this specified report parameters. /// </summary> /// <returns></returns> public static string GetBaseCompanyTimeZoneIdentifier(string reportPath, List <ParameterValue> parameters, string defaultTimeZone) { if (string.IsNullOrEmpty(reportPath)) { throw new ArgumentNullException("reportPath"); } if (parameters == null) { throw new ArgumentNullException("parameters"); } string baseCoTimeZone = defaultTimeZone; //when needed, BaseCo time zone is an internal parameter to the RDL, //if it is not defined, we need to use a default (server time zone). using (var ssrs = new ReportingService2005()) { //HACK: To get around issues between DEV-DB02 and the DC, use a local user if (0 == string.Compare(System.Configuration.ConfigurationManager.AppSettings["ReportServerUseDefaultCredentials"], "FALSE", StringComparison.OrdinalIgnoreCase)) { ssrs.UseDefaultCredentials = false; ssrs.Credentials = new NetworkCredential( System.Configuration.ConfigurationManager.AppSettings["ReportServerUserName"], System.Configuration.ConfigurationManager.AppSettings["ReportServerPassword"]); } else { ssrs.UseDefaultCredentials = true; } //first, get default report parameters var prms = ssrs.GetReportParameters( reportPath, null, true, null, null); //use those values to calculate actual report parameters var actualParameterValues = from p in prms where p.PromptUser == true //just skip internal parameters join v in parameters on p.Name equals v.Name select new ParameterValue { Name = p.Name, Value = Report._GetActualParameterValue(p, v) }; //finally, retrieve parameters again, which will evaluate all defaults prms = ssrs.GetReportParameters( reportPath, null, true, actualParameterValues.ToArray(), null); //extract base tranco time zone baseCoTimeZone = (from p in prms where p.Name == "BaseTranCo_TZ" where p.DefaultValues != null where p.DefaultValues.Length > 0 select p.DefaultValues[0]) .DefaultIfEmpty(defaultTimeZone) .FirstOrDefault(); } return(baseCoTimeZone); }
public static IEnumerable <ReportParameterViewItem> GetReportParameters( string reportId, IEnumerable <ParameterValue> parameterValues, GetReportParameterOptions options, int userId, int?clientId, ReportingApplication application, ReportingEnvironmentEnum environment) { //load report info to get the SSRS path Report report = LoadReport(reportId, userId, clientId, application, environment); if (report == null) { throw new KeyNotFoundException(string.Format("The report was not found: {0}", reportId)); } string path = report.GetSpecificReportPath(parameterValues); using (var ssrs = new ReportingService2005()) { //HACK: To get around issues between DEV-DB02 and the DC, use a local user if (0 == string.Compare(System.Configuration.ConfigurationManager.AppSettings["ReportServerUseDefaultCredentials"], "FALSE", StringComparison.OrdinalIgnoreCase)) { ssrs.UseDefaultCredentials = false; ssrs.Credentials = new NetworkCredential( System.Configuration.ConfigurationManager.AppSettings["ReportServerUserName"], System.Configuration.ConfigurationManager.AppSettings["ReportServerPassword"]); } else { ssrs.UseDefaultCredentials = true; } //first, get default report parameters var prms = ssrs.GetReportParameters( path, null, true, null, null); //build a list of dependent parameters var dependentPrms = from p in prms where p.Dependencies != null from d in p.Dependencies where (from q in prms where q.Name == d where q.PromptUser select q).Any() //Do not include internal parameters as dependencies as the UI does not need to refresh. select new { ParameterName = d, Dependent = p.Name }; //if parameter values were specified, calculate "actual" values and validate again if (parameterValues != null) { var actualParameterValues = from p in prms join v in parameterValues on p.Name equals v.Name select new ParameterValue { Name = p.Name, Value = _GetActualParameterValue(p, v) }; prms = ssrs.GetReportParameters( path, null, true, actualParameterValues.ToArray(), null); } //build view item list var prmViewItems = from p in prms where p.PromptUser //don't return internal (read-only) parameters join v in parameterValues ?? new List <ParameterValue>() on p.Name equals v.Name into pvGroup from pv in pvGroup.DefaultIfEmpty(GetDefaultParameterValue(p)) let dependents = from d in dependentPrms where d.ParameterName == p.Name select d.Dependent select new ReportParameterViewItem(p, pv, dependents.ToArray()); //return view items depending on the options specified return (from p in prmViewItems where (GetReportParameterOptions.IncludeAllParameters == (options & GetReportParameterOptions.IncludeAllParameters)) || p.IsVisible == (options == GetReportParameterOptions.IncludeVisibleParameters) select p); } }
//formatType must be: EXCEL, PDF, WORD, CSV, XML, RTF public static void SaveRDL(string reportName, string formatType, Dictionary <string, string> dictValues, string _fileName, SSRSServer server = SSRSServer.New2016) { // Authenticate to the Web service using Windows credentials var netCredentials = new System.Net.NetworkCredential("<windowsUserName>", "<windowsUserPassword>", "<Domain>"); // Create a new proxy to the web service ReportingService2005 rs = new ReportingService2005() { Credentials = netCredentials }; RE2005.ReportExecutionService rsExec = new RE2005.ReportExecutionService() { Credentials = netCredentials }; if (server == SSRSServer.New2016) { rs.Url = $"http://<server>/reportservice2005.asmx"; rsExec.Url = $"http://<server>/reportexecution2005.asmx"; } else { rs.Url = $"http://<server>/reportservice2005.asmx"; rsExec.Url = $"http://<server>/reportexecution2005.asmx"; } string historyId = null; bool forRendering = false; ParameterValue[] values = null; DataSourceCredentials[] credentials = null; ReportParameter[] _parameters = null; byte[] results; try { _parameters = rs.GetReportParameters(reportName, historyId, forRendering, values, credentials); if (_parameters != null) { foreach (ReportParameter rp in _parameters) { Console.WriteLine("Name: {0}", rp.Name); } } RE2005.ParameterValue[] parameters = new RE2005.ParameterValue[dictValues.Count]; int count = 0; foreach (var item in dictValues) { parameters[count] = new RE2005.ParameterValue(); parameters[count].Label = item.Key; parameters[count].Name = item.Key; parameters[count++].Value = item.Value; } RE2005.ExecutionInfo rpt = rsExec.LoadReport(reportName, null); rsExec.SetExecutionParameters(parameters, "en-us"); //Render variables string deviceInfo = null; string encoding = String.Empty; string mimeType = String.Empty; string extension = String.Empty; RE2005.Warning[] warnings = null; string[] streamIDs = null; string formatType2Pass; switch (formatType) { case "RTF": formatType2Pass = "******"; //And we convert afterwards break; case "DOCX": formatType2Pass = "******"; break; default: formatType2Pass = formatType; break; } results = rsExec.Render( formatType2Pass, deviceInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs); string fileNameExt; switch (formatType) { case "EXCEL": fileNameExt = ".XLSX"; break; case "WORDOPENXML": fileNameExt = ".DOCX"; break; case "WORD": fileNameExt = ".DOC"; break; case "RTF": fileNameExt = ".DOC"; //And we convert afterwards break; case "PDF": default: fileNameExt = "." + formatType; break; } string fileName = (Path.GetExtension(_fileName) == "") ? _fileName + fileNameExt : _fileName; using (FileStream stream = File.OpenWrite(fileName)) { stream.Write(results, 0, results.Length); stream.Dispose(); } if (formatType == "RTF") { string fileNameRTF = _fileName + ".rtf"; WordToRtf(fileName, fileNameRTF); } File.SetAttributes(fileName, FileAttributes.Normal); rs.Dispose(); rsExec.Dispose(); } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.Message); } }
public static byte[] SaveRDLtoFileStream(string reportName, string formatType, Dictionary <string, string> dictValues) { // Create a new proxy to the web service ReportingService2005 rs = new ReportingService2005(); RE2005.ReportExecutionService rsExec = new RE2005.ReportExecutionService(); // Authenticate to the Web service using Windows credentials rs.Credentials = System.Net.CredentialCache.DefaultCredentials; rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials; rs.Url = "http://<server>/reportservice2005.asmx"; rsExec.Url = "http://<server>/reportexecution2005.asmx"; string historyId = null; bool forRendering = false; ParameterValue[] values = null; DataSourceCredentials[] credentials = null; ReportParameter[] _parameters = null; byte[] results = new byte[64 * 1024]; try { _parameters = rs.GetReportParameters(reportName, historyId, forRendering, values, credentials); if (_parameters != null) { foreach (ReportParameter rp in _parameters) { Console.WriteLine("Name: {0}", rp.Name); } } RE2005.ParameterValue[] parameters = new RE2005.ParameterValue[dictValues.Count]; int count = 0; foreach (var item in dictValues) { parameters[count] = new RE2005.ParameterValue(); parameters[count].Label = item.Key; parameters[count].Name = item.Key; parameters[count++].Value = item.Value; } RE2005.ExecutionInfo rpt = rsExec.LoadReport(reportName, null); rsExec.SetExecutionParameters(parameters, "en-us"); //Render variables string deviceInfo = null; string encoding = String.Empty; string mimeType = String.Empty; string extension = String.Empty; RE2005.Warning[] warnings = null; string[] streamIDs = null; results = rsExec.Render( formatType, deviceInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs); return(results); } catch (Exception e) { //Console.WriteLine(e.Message); } return(results); }
private void GetParameters_Load(object sender, EventArgs e) { rs = new ReportingService2005(); rs.Credentials = System.Net.CredentialCache.DefaultCredentials; bool forRendering = true; string historyID = null; ParameterValue[] values = null; DataSourceCredentials[] credentials = null; ReportParameter[] parametersSSRS = null; ValidValue[] pvs = null; int x = 5; int y = 30; try { parametersSSRS = rs.GetReportParameters(report, historyID, forRendering, values, credentials); if (parametersSSRS != null) { foreach (ReportParameter rp in parametersSSRS) { this.SuspendLayout(); this.parameterPanel.SuspendLayout(); this.parameterPanel.SendToBack(); // now create a label for the combo box below Label lbl = new Label(); lbl.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left); lbl.Location = new System.Drawing.Point(x, y); lbl.Name = rp.Name; lbl.Text = rp.Name; lbl.Size = new System.Drawing.Size(150, 20); this.parameterPanel.Controls.Add(lbl); x = x + 150; // now make a combo box and fill it ComboBox a = new ComboBox(); a.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right); a.Location = new System.Drawing.Point(x, y); a.Name = rp.Name; a.Size = new System.Drawing.Size(200, 20); x = 5; y = y + 30; this.parameterPanel.Controls.Add(a); this.parameterPanel.ResumeLayout(false); this.ResumeLayout(false); if (rp.ValidValues != null) { //Build listitems ArrayList aList = new ArrayList(); pvs = rp.ValidValues; foreach (ValidValue pv in pvs) { aList.Add(new ComboItem(pv.Label, pv.Value)); } //Bind listitmes to combobox a.DataSource = aList; a.DisplayMember = "Display"; a.ValueMember = "Value"; } } } } catch (SoapException ex) { MessageBox.Show(ex.Detail.InnerXml.ToString()); } }
private ReportParameter[] GetReportParameters(ParameterValue[] values) { string serverUrl; string modelsFolder; string company; string languageCulture; ReportParameter[] parameters = null; string errMsg = null; try { ReportUtility.GetSessionInfo(out serverUrl, out modelsFolder, out company, out languageCulture); if (string.IsNullOrEmpty(serverUrl)) { throw new InvalidOperationException(Resources.GetString(Report.NoServerUrl)); } ReportSettings settings = new ReportSettings(); settings.ReportManagerUrl = serverUrl; settings.RootFolder = modelsFolder; settings.ReportPath = this.ReportPath; string fullPath = settings.ResolveFullPath(); // Ask reporting services for a list of all reports and all the parameters for the currently selected report. using (ReportingService2005 rs = new ReportingService2005()) { // Provoke potential exceptions by validating the full path settings.ValidateFullPath(fullPath); rs.Url = settings.ResolvedServiceUrl; rs.Credentials = System.Net.CredentialCache.DefaultCredentials; parameters = rs.GetReportParameters(fullPath, null, values != null, values, null); } } catch (System.Net.WebException) { errMsg = Resources.GetString(Report.cant_read_from_server); } catch (InvalidOperationException reportException) { errMsg = Microsoft.SharePoint.Utilities.SPHttpUtility.HtmlEncode(reportException.Message); } catch (ReportException reportException) { errMsg = AxRSReportWebPart.FormatMissingReportExceptionMessage( reportException, this.WebPartToEdit.CultureInfo, this.WebPartToEdit.Title, this.ReportPath); } catch (Exception exception) { errMsg = Microsoft.SharePoint.Utilities.SPHttpUtility.HtmlEncode(exception.Message); } if (!string.IsNullOrEmpty(errMsg)) { this.AddErrorMessage(errMsg); } return(parameters); }
private ReportParameter[] GetReportParameters(ParameterValue[] values) { string serverUrl; string modelsFolder; string company; string languageCulture; ReportParameter[] parameters = null; string errMsg = null; try { ReportUtility.GetSessionInfo(out serverUrl, out modelsFolder, out company, out languageCulture); if (string.IsNullOrEmpty(serverUrl)) { throw new InvalidOperationException(Resources.GetString(Report.NoServerUrl)); } ReportSettings settings = new ReportSettings(); settings.ReportManagerUrl = serverUrl; settings.RootFolder = modelsFolder; settings.ReportPath = this.ReportPath; string fullPath = settings.ResolveFullPath(); // Ask reporting services for a list of all reports and all the parameters for the currently selected report. using (ReportingService2005 rs = new ReportingService2005()) { // Provoke potential exceptions by validating the full path settings.ValidateFullPath(fullPath); rs.Url = settings.ResolvedServiceUrl; rs.Credentials = System.Net.CredentialCache.DefaultCredentials; parameters = rs.GetReportParameters(fullPath, null, values != null, values, null); } } catch (System.Net.WebException) { errMsg = Resources.GetString(Report.cant_read_from_server); } catch (InvalidOperationException reportException) { errMsg = Microsoft.SharePoint.Utilities.SPHttpUtility.HtmlEncode(reportException.Message); } catch (ReportException reportException) { errMsg = AxRSReportWebPart.FormatMissingReportExceptionMessage( reportException, this.WebPartToEdit.CultureInfo, this.WebPartToEdit.Title, this.ReportPath); } catch (Exception exception) { errMsg = Microsoft.SharePoint.Utilities.SPHttpUtility.HtmlEncode(exception.Message); } if (!string.IsNullOrEmpty(errMsg)) { this.AddErrorMessage(errMsg); } return parameters; }