2015-09-29 99 views
0

我用下面的代碼從一個應用程序調用RDLC文件到另一個應用程序。下面的代碼駐留在一個應用程序中。 RDLC文件駐留在另一個應用程序中。如何在asp.net中爲RDLC ReportPath設置動態url?

Dim RptVwr As New Microsoft.Reporting.WebForms.ReportViewer() 
Dim ds As DataSet = OBJ.GetInventoryProductDetails(plannerCode) 
Dim RptDtSrc As New Microsoft.Reporting.WebForms.ReportDataSource() 
RptDtSrc.Name = "XXXXXX1" 
RptDtSrc.Value = ds.Tables(0) 
RptVwr.LocalReport.DataSources.Add(RptDtSrc) 

Dim RptDtSrc1 As New Microsoft.Reporting.WebForms.ReportDataSource() 
RptDtSrc1.Name = "XXXXXX2" 
RptDtSrc1.Value = ds.Tables(1) 
RptVwr.LocalReport.DataSources.Add(RptDtSrc1) 

RptVwr.LocalReport.ReportPath = "http://localhost:58154/RDLC/GLA_InspectionList.rdlc" 
RptVwr.LocalReport.EnableHyperlinks = True 
Dim excelcontent As Byte() = RptVwr.LocalReport.Render("Excel", Nothing, Nothing, Nothing, Nothing, Nothing, Nothing) 

Dim FS As FileStream 
FS = New FileStream(Save, FileMode.Create) 
FS.Write(excelcontent, 0, excelcontent.Length) 
FS.Close() 

但是上面的代碼在excel文件生成過程中失敗。如何解決上述問題?

+0

我看到你編輯了你的文章。請進一步解釋你的意思是「上面的代碼在excel文件生成過程中失敗」。你有錯誤嗎?如果是這樣,什麼錯誤以及它在哪裏拋出?或者你得到一個空的Excel文件?還是什麼都沒有發生? – Oceans

+0

您正在使用pdfcontent而不是excelcontent。你在哪裏試圖保存這個文件? – tezzo

+0

@tezzo,我在應用程序中保存了生成的excel文件。 – RGS

回答

0

我相信你忘了添加DataSource,所以你沒有什麼可以顯示在你的報告上。

RptVwr.LocalReport.DataSources.Add(myDataSource) 

更新:我認爲,這個問題可能是由第二個項目在DataSet中使用不同類別的事實引起的。確保你使用了正確的類和屬性。

也許你可以通過添加一個簡單的數據源來測試它。例如沿着這樣的線:

RptVwr.LocalReport.Add(New ReportDataSource("MyClass", New List(Of [MyClass])() From { _ 
    New [MyClass]() With { _ 
     Key .MyProp = "MyProp" _ 
    } _ 
})) 
+0

我已更新我的問題。好心檢查。 – RGS

+0

我看到了,請添加更多關於此問題的信息,以便我可以根據需要更新我的答案。你有什麼錯誤嗎? – Oceans

+0

我在執行過程中遇到了錯誤呈現報告問題。 – RGS

相關問題