【问题标题】:Getting Values from web.config file to rdlc report?从 web.config 文件获取值到 rdlc 报告?
【发布时间】:2015-04-23 11:59:29
【问题描述】:

如何从 web.config (appsettings) 文件中获取值到我的 rdlc 报告中? 我需要在我的 rdlc 发票中显示来自 web.config 文件的多个值?我怎样才能上这个?

<add key="siteName" value="desktopapplications" />
<add key="companyName" value="ProSoftware Limited" />

rdlc里面的代码哪里可以写,上面的值如何实现?

我知道如何将值从 web.config 获取到 .cs 页面

string siteName= WebConfigurationManager.AppSettings["siteName"]

它在 rdlc 中是如何工作的?任何帮助谢谢

【问题讨论】:

    标签: c# sql asp.net asp.net-mvc rdlc


    【解决方案1】:

    在 RDLC 设计器的“报告数据”面板中,为 siteName 和 companyName 添加参数。在后面的代码中:

    Dim myReport As New LocalReport
    Dim params() As ReportParameter = New ReportParameter(1) {}
         params(0) = New ReportParameter("siteName", siteName)
         params(1) = New ReportParameter("companyName", companyName)
    With myReport
        .ReportPath = ReportPath '"MyReport.rdlc"
        .DataSources.Clear()
        .DataSources.Add(mydatasource)
        .Refresh()
        .SetParameters(params)
    End With
    

    【讨论】:

      【解决方案2】:

      来自朗普罗瑟的回答

             using (var lr = new LocalReport())
              {
      
                  var path = Path.Combine(HttpRuntime.AppDomainAppPath, "Report", "MyInvoice.rdlc");
                  lr.ReportPath = path;
                  var siteName = ConfigurationManager.AppSettings["siteName"];
                  var companyName = ConfigurationManager.AppSettings["companyName"];
      
                  var @params = new ReportParameter[2];
      
                  @params[0] = new ReportParameter("siteName", siteName);
                  @params[1] = new ReportParameter("companyName",companyName);
                  var usersinv = db.Invoices.Where(i => i.Id == invoiceid.Id);
                  var invoice = usersinv.SingleOrDefault();
                  if (invoice != null)
                  {
                      var invoiceitems = db.InvoiceItems.Where(i => i.InvoiceId == invoiceid.Id);
                      var rd1 = new ReportDataSource("Invoice", usersinv);
                      var rd2 = new ReportDataSource("InvoiceItems", invoiceitems.ToList());
      
                      lr.DataSources.Add(rd1);
                      lr.DataSources.Add(rd2);
                      lr.SetParameters(@params);
                  }
                  string encoding;
                  string fileNameExtention;
      
                  const string deviceInfo =
                  "<DeviceInfo>" +
                  "  <OutputFormat>PDF</OutputFormat>" +
                  "  <PageWidth>21cm</PageWidth>" +
                  "  <PageHeight>29.7cm</PageHeight>" +
                  "  <MarginTop>0.0cm</MarginTop>" +
                  "  <MarginLeft>0.0cm</MarginLeft>" +
                  "  <MarginRight>0.0cm</MarginRight>" +
                  "  <MarginBottom>0.0cm</MarginBottom>" +
                  "</DeviceInfo>";
      
                  Microsoft.Reporting.WebForms.Warning[] warnings;
                  string[] streams;
      
                  renderedBytes = lr.Render("PDF",
                      deviceInfo,
                      out mimeType,
                      out encoding,
                      out fileNameExtention,
                      out streams,
                      out warnings);
      
      
              }
              return File(renderedBytes, mimeType);
      

      现在,PDF发票中的参数将被web.config文件调用

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-12-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多