2017-03-08 93 views
0

我試圖在C#中使用報告工作。我試圖嵌入我的RDLC文件,例如:處理「非法路徑」中的C#報告錯誤

var reportDataSource = new ReportDataSource("ProspectsDataSet", _allProspects); 
ReportViewer.LocalReport.DataSources.Add(reportDataSource); 

ReportViewer.LocalReport.ReportEmbeddedResource = "SdcDatabase.Modules.EnquiryModule.View.Reports.ProspectsReport.rdlc"; 
ReportViewer.ZoomMode = ZoomMode.PageWidth; 
ReportViewer.RefreshReport(); 

在RDLC文件本身的生成操作設置爲嵌入的資源,並複製到輸出目錄設置爲始終複製。

我有雙重檢查,我敢肯定,這是ReportEmbeddedResource字符串中的正確命名空間。然而,當我嘗試加載的報告中,我得到這個錯誤:

enter image description here

我曾嘗試在路徑切換周圍的幾件事情,如更換「」與'/'和'\',但到目前爲止我還沒有能夠得到任何解決這個問題。我也嘗試使用LocalPath而不是EmbeddedResource,但我又遇到了錯誤。

我已經搜索了這個問題,但到目前爲止還沒有找到任何解決我的問題。

+0

https://social.msdn.microsoft.com/Forums/zh-CN/7b259014-9bb2-424a-9c5b-37be2fcb1bef/how-to-use-reportembeddedresource-in-reportviewer-webform-control?forum=vsreportcontrols – mm8

回答

0

我有一個報告包裝類,適用於我的應用程序。我有一個屬性來保存我想運行的「.rdlc」報告定義的名稱。然後,當我調用我的「RunReport()」方法時,我根據從應用程序程序集資源中讀取流來分配報告。你有什麼短的版本可能

ReportViewer.LocalReport.LoadReportDefinition(GetRDLCStream("ProspectsReport.rdlc")); 

然後,下,我有一個方法

private Stream GetRDLCStream(string rptRDLC) 
{ 
    var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(
        "SdcDatabase.Modules.EnquiryModule.View.Reports." + rptRDLC); 

    return stream; 
} 

很顯然,我不是正面的路徑的命名約定到您的項目,但我暗示上述路徑。然而,它應該反映(例如)

"NameOfYourApp.SubFolderWithinPath.MaybeReportsSubFolder." + actualReport.RDLC name 

這樣一來,我從來沒有擔心複製出來的資源,希望的路徑工作。我知道它是嵌入式的,也是組裝中的什麼地方。