0

rdlcレポートの結果をファイルに書き込むMVCコントローラーメソッドがあります。これは私のローカルマシンでは正常に機能しますが、本番環境に公開されると、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 に答える