/// <summary> /// Builds the tree node. /// </summary> /// <param name="item">The item.</param> /// <param name="expandedItems">The expanded items.</param> /// <param name="treeBuilder">The tree builder.</param> private void BuildTreeNode(ReportingServiceItem item, List <string> expandedItems, ref StringBuilder treeBuilder) { string iconClass; string nodeIdPrefix; string viewerUrl = null; switch (item.Type) { case ItemType.Folder: iconClass = "fa-folder-o"; nodeIdPrefix = "f-"; break; case ItemType.Report: iconClass = "fa-file-text-o"; nodeIdPrefix = "r-"; if (!string.IsNullOrWhiteSpace(GetAttributeValue("ReportViewerPage"))) { var qsParams = new Dictionary <string, string>(); qsParams.Add("ReportPath", HttpUtility.UrlEncode(item.Path)); viewerUrl = LinkedPageUrl("ReportViewerPage", qsParams); } break; default: return; } var nodeId = string.Concat(nodeIdPrefix, item.Path); var listItemFormat = "<li data-expanded=\"{0}\" data-id=\"{1}\" data-type=\"{5}\"><span><span class=\"rollover-container\"><i class=\"fa {4}\"></i> {2} </span></span>{3}"; var reportItemLink = string.IsNullOrWhiteSpace(viewerUrl) ? item.Name : string.Format("<a href=\"{0}\">{1}</a>", viewerUrl, item.Name); treeBuilder.AppendFormat(listItemFormat, expandedItems.Any(s => item.Path.Equals(s)).ToString().ToLower(), nodeId, reportItemLink, Environment.NewLine, iconClass, item.Type.ToString()); if (item.Children != null && item.Children.Count(c => c.Type != ItemType.DataSource) > 0) { treeBuilder.AppendLine("<ul>"); foreach (ReportingServiceItem child in item.Children) { BuildTreeNode(child, expandedItems, ref treeBuilder); } treeBuilder.AppendLine("</ul>"); } treeBuilder.AppendLine("</li>"); }
/// <summary> /// Loads the report. /// </summary> private void LoadReport() { pnlPdfViewer.Visible = false; phViewer.Controls.Clear(); var provider = new ReportingServicesProvider(); var reportPath = GetReportPath(provider); lReportTitle.Text = "Report Viewer"; if (string.IsNullOrWhiteSpace(reportPath)) { SetError("Report Path Error", "Report Path is required."); return; } var rsItem = ReportingServiceItem.GetItemByPath(reportPath); if (rsItem == null) { SetError("Report Path Error", "Report Not Found"); return; } var paramNames = ReportingServiceItem.GetReportParameterList(provider, reportPath); lReportTitle.Text = string.Format("{0} Viewer", rsItem.Name); var paramValues = new Dictionary <string, string>(); var paramAttribute = GetAttributeValue("ReportParameters").AsDictionaryOrNull(); foreach (var pn in paramNames) { string paramValue = null; if (paramAttribute != null) { paramValue = paramAttribute .Where(a => a.Key.Equals(pn, StringComparison.InvariantCultureIgnoreCase)) .Select(a => a.Value) .FirstOrDefault(); } if (!string.IsNullOrWhiteSpace(paramValue)) { paramValue = HttpUtility.UrlEncode(paramValue); } else { paramValue = PageParameter(pn); } if (!string.IsNullOrWhiteSpace(paramValue)) { paramValues.Add(pn, paramValue); } } var urlBuilder = new StringBuilder(); urlBuilder.AppendFormat("{0}?reportPath={1}", ResolveRockUrlIncludeRoot("~/Plugins/rocks_kfs/Reporting/GetReportingServicesPDF.ashx"), reportPath); foreach (var param in paramValues) { urlBuilder.AppendFormat("&{0}={1}", param.Key, param.Value); } if (!mRenderPDFOnly) { var iframeTag = string.Format("<iframe src=\"{0}\" id=\"ifReportPDF\" class=\"col-sm-12\"></iframe>", urlBuilder.ToString()); phViewer.Controls.Add(new LiteralControl(iframeTag)); pnlPdfViewer.Visible = true; } else { var pdfBytes = GetPDFStream(urlBuilder.ToString()); base.Response.Clear(); var dispositionType = string.Empty; if (pdfBytes == null) { base.Response.StatusCode = 404; } else { base.Response.AppendHeader("content-length", (pdfBytes.Length).ToString()); //base.Resp base.Response.AppendHeader("content-disposition", string.Format("filename={0}.pdf", rsItem.Name)); base.Response.ContentType = "applicaton/pdf"; base.Response.OutputStream.Write(pdfBytes, 0, pdfBytes.Length); } base.Response.Flush(); base.Response.Close(); base.Response.End(); } }
public ReportingServiceItem GetReportTree(string rootPath, bool getChildren, bool includeHidden) { return(ReportingServiceItem.GetReportTree(rootPath, getChildren, includeHidden)); }
public ReportingServiceItem GetReportTree() { return(ReportingServiceItem.GetReportTree("", true, true)); }
public ReportingServiceItem GetFolderTree() { return(ReportingServiceItem.GetFoldersTree("", true, true)); }
/// <summary> /// Builds the tree. /// </summary> private void BuildTree() { try { var expandedItems = new List <string>(); var selectedItemPath = PageParameter("ReportPath"); if (!string.IsNullOrWhiteSpace(selectedItemPath)) { selectedItemPath = HttpUtility.UrlDecode(selectedItemPath); var selectedItem = ReportingServiceItem.GetItemByPath(selectedItemPath); if (selectedItem != null && selectedItem.Type == ItemType.Report) { hfSelectedItem.Value = string.Concat("r-", selectedItemPath); } else if (selectedItem != null && selectedItem.Type == ItemType.Folder) { hfSelectedItem.Value = string.Concat("f-", selectedItemPath); } } ReportingServiceItem reportItem = null; if (hfSelectionType.Value.Equals("Folder")) { reportItem = ReportingServiceItem.GetFoldersTree(rootFolder, showChildItems, showHiddenItems); } else if (hfSelectionType.Value.Equals("Report")) { reportItem = ReportingServiceItem.GetReportTree(rootFolder, showChildItems, showHiddenItems); } // also get any additional expanded nodes var expandedItemParams = PageParameter("ExpandedItems"); if (!string.IsNullOrWhiteSpace(expandedItemParams)) { foreach (var id in expandedItemParams.Split(',').ToList()) { if (!expandedItems.Contains(id)) { expandedItems.Add(id); } } } hfExpandedItems.Value = expandedItems.AsDelimited(","); var treeBuilder = new StringBuilder(); treeBuilder.AppendLine("<ul id=\"treeview\">"); BuildTreeNode(reportItem, expandedItems.Select(s => s.Substring(2)).ToList(), ref treeBuilder); treeBuilder.AppendLine("</ul>"); lFolders.Text = treeBuilder.ToString(); } catch (System.Net.WebException webEx) { if (((System.Net.HttpWebResponse)webEx.Response).StatusCode == System.Net.HttpStatusCode.Unauthorized) { ShowError("Authorization Error", "Browser User Could not authenticate to Reporting Server."); } } catch (System.ServiceModel.Security.MessageSecurityException ex) { ShowError("Authorization Error", "Browser User could not authenticate to Reporting Server."); } catch (System.ServiceModel.EndpointNotFoundException ex) { ShowError("Connection Error", "An error occurred when connecting to the reporting server."); } }
/// <summary> /// Loads the report. /// </summary> private void LoadReport() { string reportPath = null; const string pageTitleFormat = "{0} Report Viewer"; var reportPathAttribute = GetAttributeValue("ReportPath"); var reportParamAttributes = GetAttributeValue("ReportParameters").AsDictionaryOrNull(); if (!string.IsNullOrWhiteSpace(reportPathAttribute)) { reportPath = reportPathAttribute; } else if (!string.IsNullOrWhiteSpace(PageParameter("reportPath"))) { reportPath = PageParameter("reportPath"); reportPath = Server.UrlDecode(reportPath); } else { pnlReportViewer.Visible = false; lReportTitle.Text = string.Format(pageTitleFormat, string.Empty).Trim(); return; } var rsItem = ReportingServiceItem.GetItemByPath(reportPath); if (rsItem == null) { ShowError("Error", "Report Not Found"); pnlReportViewer.Visible = false; lReportTitle.Text = string.Format(pageTitleFormat, string.Empty).Trim(); return; } lReportTitle.Text = string.Format(pageTitleFormat, rsItem.Name); var provider = new ReportingServicesProvider(); rsViewer.ProcessingMode = ProcessingMode.Remote; rsViewer.Height = Unit.Percentage(98); rsViewer.Width = Unit.Percentage(100); var report = rsViewer.ServerReport; report.ReportServerUrl = new Uri(provider.ServerUrl); report.ReportPath = reportPath; report.ReportServerCredentials = provider.GetBrowserCredentials(); var reportParams = new List <ReportParameter>(); foreach (ReportParameterInfo parameter in report.GetParameters()) { string paramValue = null; if (reportParamAttributes != null && reportParamAttributes.ContainsKey(parameter.Name)) { paramValue = reportParamAttributes[parameter.Name]; } else if (!string.IsNullOrWhiteSpace(PageParameter(parameter.Name))) { paramValue = PageParameter(parameter.Name); } if (!string.IsNullOrWhiteSpace(paramValue)) { reportParams.Add(new ReportParameter(parameter.Name, paramValue)); } } if (reportParams.Count > 0) { report.SetParameters(reportParams.ToArray()); report.Refresh(); } pnlReportViewer.Visible = true; }
/// <summary> /// Handles the Click event of the btnConfigure control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void btnConfigure_Click(object sender, EventArgs e) { ReportingServiceItem.GetFoldersTree("", true, true); }