2011-01-31 87 views
1

我很難在我的應用程序中使用reportviewer顯示子報表。它在本地調試時可以很好地工作。但是當我將它上傳到服務器時,子報告是空白的。當RDLC移動到服務器時丟失子報表

我相信SubreportProcessing事件不會觸發,因爲我沒有看到從SQL Server Profiler觸發存儲過程。這是我正在使用的代碼。

private void RunReport(string strFormat, int PlanID) 
    { 
     const string reportrdlc = "Reports\\Report_All_Sections.rdlc"; 
     LocalReport report = new LocalReport {ReportPath = Server.MapPath(reportrdlc)}; 
     report.SetBasePermissionsForSandboxAppDomain(new PermissionSet(PermissionState.Unrestricted)); 
     report.DataSources.Clear(); 
     report.SubreportProcessing += SetSubDataSource; 

     report.DataSources.Add(new ReportDataSource("DataSet_usp_GetSD", _wpt.Get_SD(PlanID).Copy())); 

     report.Refresh(); 

     string mimeType; 
     string encoding; 
     string fileNameExtension; 
     string[] streams; 
     Warning[] warnings; 

     byte[] pdfContent = report.Render(strFormat, null, out mimeType, out encoding, 
        out fileNameExtension, out streams, out warnings); 

     System.IO.MemoryStream stream = new System.IO.MemoryStream(pdfContent); 
     Response.ContentType = strFormat == "EXCEL" ? "application/vnd.ms-excel" : "application/pdf"; 

     Response.BinaryWrite(stream.ToArray()); 
     Response.Flush(); 
     Response.Close(); 
     stream.Close(); 

    } 
    public void SetSubDataSource(object sender, SubreportProcessingEventArgs e) 
    { 
     int PlanID = 1; 
     if (Request.QueryString["PlanID"] != null) 
     { 
      try 
      { 
       PlanID = Convert.ToInt32(Request.QueryString["PlanID"]); 
      } 
      catch (Exception Ex) 
      { 
       PlanID = 1; 
      } 
     } 
     switch (e.ReportPath) 
     { 
      case "Report_All_Mentor": 
       e.DataSources.Add(new ReportDataSource("DataSet_usp_GetMC", _wpt.Get_MC(PlanID).Copy())); 
       break; 
      case "Report_All_Intern": 
       e.DataSources.Add(new ReportDataSource("DataSet_usp_GetEA", _wpt.Get_EA(PlanID).Copy())); 
       break; 
     } 


    } 
+0

您是否找到了解決方案呢? – Cyberdrew 2011-02-22 21:47:00

回答

1

我似乎有同樣的問題。我認爲問題在於,當部署reportPath包含報告的完整路徑時,但在本地調試時,它只傳遞報告名稱。

是否有可能您的SubreportProcessing事件確實觸發,但在您的switch語句中,非情況與reportPath參數中包含的完整路徑相匹配。

我不知道如何解決,但我認爲這可能是根本原因。