0

我有一个 MVC 控制器方法,它将 rdlc 报告的结果写入文件。这在我的本地机器上运行良好,但是当它发布到生产环境时,它会在 setparameters 行上停止执行并且不会触发异常。任何线索将不胜感激。

    public JsonResult GenerateSignInSheet(string id)
    {
        try
        {
            string pgmid = id;
            string strProgDate = "";
            DateTime? dtProgDate = null;
            Program prog = db.Programs.SingleOrDefault(p => p.ProgramID == pgmid);
            if (prog != null)
                dtProgDate = prog.ProgDate;
            if (dtProgDate != null)
                strProgDate = String.Format("{0:d}", dtProgDate);

            string strProgLoc = string.Empty;
            var locInfo = this.dc.usp_ProgramLocSiteInfo(id).SingleOrDefault();
            if (locInfo != null) strProgLoc = locInfo.VendorOrHost ?? string.Empty;

            //Rep information
            string strRepName = string.Empty;

            LocalReport localReport = new LocalReport();

            // the following 2 lines will allow globals to work - MS gotcha
            System.Security.PermissionSet sec = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted);
            localReport.SetBasePermissionsForSandboxAppDomain(sec);

            localReport.ReportPath = Server.MapPath("~/Content/Reports/RptSignInSheetPrefilled.rdlc");
            var sourceList = dc.GetRSVPListForSignin(pgmid).ToList();
            ReportDataSource reportDataSource = new ReportDataSource("DataSetRSVPList", sourceList);
            ReportParameter p1 = new ReportParameter("ProgramID", pgmid);
            ReportParameter p2 = new ReportParameter("ProgDate", strProgDate);
            ReportParameter p3 = new ReportParameter("LocName", strProgLoc);
            ReportParameter p4 = new ReportParameter("RepName", strRepName);

            localReport.SetParameters(new ReportParameterCollection { p1, p2, p3, p4 });
            localReport.DataSources.Add(reportDataSource);

            //string reportType = "PDF";
            string mimeType;
            string encoding;
            string fileNameExtension;

            //The DeviceInfo settings should be changed based on the reportType
            //http://msdn2.microsoft.com/en-us/library/ms155397.aspx

            string deviceInfo =

            "<DeviceInfo>" +
            "  <OutputFormat>PDF</OutputFormat>" +
            "  <PageWidth>11in</PageWidth>" +
            "  <PageHeight>8.5in</PageHeight>" +
            "  <MarginTop>0.5in</MarginTop>" +
            "  <MarginLeft>0.5in</MarginLeft>" +
            "  <MarginRight>0.5in</MarginRight>" +
            "  <MarginBottom>0.5in</MarginBottom>" +
            "</DeviceInfo>";

            Warning[] warnings;
            string[] streams;
            byte[] renderedBytes;

            //Render the report
            renderedBytes = localReport.Render(
                "PDF",
                deviceInfo,
                out mimeType,
                out encoding,
                out fileNameExtension,
                out streams,
                out warnings);

            string strPDFOutputPath = System.Configuration.ConfigurationManager.AppSettings["PDFDocumentsPath"].ToString();
            string strPDFFilename = strPDFOutputPath + id.Replace("-", string.Empty) + ".pdf";

            System.IO.FileStream fs = new System.IO.FileStream(strPDFFilename, System.IO.FileMode.Create);
            fs.Write(renderedBytes, 0, renderedBytes.Length);
            fs.Close();
            fs.Dispose();


            //var theFile = File(renderedBytes, mimeType);

            return Json(new { File = strPDFFilename });

        }
        catch (Exception ex)
        {
            Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
            return Json(new { File = "" });
        }
    }
4

1 回答 1

0

您应该检查您的 dll 的版本。

我遇到了同样的问题,我的案例(Asp.Net 4 Razor,MVC)需要其中的第 11 版:

  • Microsoft.ReportViewer.Common
  • Microsoft.ReportViewer.ProcessingObjects
  • Microsoft.ReportViewer.WebForms
于 2013-04-03T12:39:56.720 回答