Calling an SSRS report from .NET without using the SSRS Server II

We already have an article that prints an .rdlc report, this article is simpler and shows only how to make the call. Too, this article targets ASP.NET. Winforms code should work the same, but the other article uses an embedded report, this uses one in the root directory. 

The report is printed to disk after processing instead of displaying it; we're going to send it to a customer via Docusign

'create the report and save to a temp location
Dim rv As New Microsoft.Reporting.WinForms.ReportViewer
rv.Reset()
rv.LocalReport.DataSources.Clear()
rv.ProcessingMode = ProcessingMode.Local
'query the database and get a datasource
Dim oDT As DataTable = SPs.fp_FPTakeoffQuote_SEL_forGrid(mintMasterNumber, App.ConnectionString).getTable
'assign the datasource to the report. The dataset name in SSRS is 'DataSet1' by default, but it might have been changed.
'the name is case sensitive
rv.LocalReport.DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", oDT))
'this code is from asp.net, the report is in the root folder
rv.LocalReport.ReportPath = Server.MapPath("TakeoffQuote.rdl")
rv.RefreshReport()
 
'write the report to disk.
Dim oByte() As Byte
oByte = rv.LocalReport.Render("pdf")
 
Dim strFileName As String = Path.Combine(Server.MapPath("FilesTEMP"), mintMasterNumber & ".pdf")
If File.Exists(strFileName) Then
    File.Delete(strFileName)
End If
'use filestream to save byte array to a file
Dim fs As New IO.FileStream(strFileName, IO.FileMode.Create)
fs.Write(oByte, 0, oByte.Length)
fs.Close()
fs = Nothing

 

 

 


RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences