using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Microsoft.Reporting.WebForms; using System.Net; using EMIS.Utility; namespace EMIS.Web.ReportViewer { public partial class Page : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (!string.IsNullOrEmpty(Request.Params["ReportFolder"])) { string reportpath = HttpUtility.HtmlDecode(Request.Params["ReportFolder"]); int aantalKeys = Request.Params.AllKeys.Length; List parameters = new List(); for (int i = 1; i < aantalKeys; i++) { string value = Request.Params[i]; string key = Request.Params.Keys[i]; if (key.Contains("_RAP")) { int index = key.IndexOf('_'); key = key.Substring(0, index); if (string.IsNullOrEmpty(value)) { ReportParameter parameter = new ReportParameter(key, (string)null); parameters.Add(parameter); } else { ReportParameter parameter = new ReportParameter(key, HttpUtility.HtmlDecode(value)); parameters.Add(parameter); } } } this.RenderReport(reportpath, parameters); } } } private void RenderReport(string reportpath, List parameters = null) { string User = Const.LOCAL_SETTING_REPORT_USER_NAME; string Pass = Const.LOCAL_SETTING_REPORT_PASSWORD; string ReportServerUrl = Const.LOCAL_SETTING_REPORT_URL; IReportServerCredentials irsc = new CustomReportCredentials(User, Pass, ""); Uri uri = new Uri(ReportServerUrl); // EVENTS //reportViewer.Load += reportViewer_Load; //reportViewer.Unload += reportViewer_Unload; if (Request.Browser.Browser.Contains("InternetExplorer")) { reportViewer.SizeToReportContent = false; } else { reportViewer.SizeToReportContent = true; } reportViewer.ShowExportControls = true; reportViewer.ShowPrintButton = true; reportViewer.ShowParameterPrompts = false; //reportViewer.Visible = true; reportViewer.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote; reportViewer.ServerReport.ReportServerCredentials = irsc; reportViewer.ServerReport.ReportServerUrl = uri; reportViewer.ServerReport.ReportPath = reportpath; if (parameters != null && parameters.Count != 0) { reportViewer.ServerReport.SetParameters(parameters); } reportViewer.ServerReport.Refresh(); } private Dictionary GetCurrentParameters() { var parameterCollection = reportViewer.ServerReport.GetParameters(); var param = new Dictionary(); foreach (var p in parameterCollection) { var name = p.Name; if (p.DataType == ParameterDataType.DateTime) { var d = Convert.ToDateTime(p.Values[0]); param[name] = d.ToString("dd-MM-yyyy"); } else { var values = p.Values.ToList(); param[name] = values; } } return param; } } public class CustomReportCredentials : IReportServerCredentials { private string _UserName; private string _PassWord; private string _DomainName; public CustomReportCredentials(string UserName, string PassWord, string DomainName) { _UserName = UserName; _PassWord = PassWord; _DomainName = DomainName; } public System.Security.Principal.WindowsIdentity ImpersonationUser { get { return null; } } public ICredentials NetworkCredentials { get { return new NetworkCredential(_UserName, _PassWord, _DomainName); } } public bool GetFormsCredentials(out Cookie authCookie, out string user, out string password, out string authority) { authCookie = null; user = password = authority = null; return false; } } }