Save an SSRS Report in html format.
-
The code below will load an rdl report from a datasource and save it as PDF. But only PDF. If I choose any other format it errors with System.ArgumentOutOfRangeException HResult=0x80131502 Message=Specified argument was out of the range of valid values. Parameter name: format Source=Microsoft.ReportViewer.WebForms ... at Microsoft.Reporting.WebForms.Report.Render(String format, String deviceInfo, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& --- I would welcome a suggestion. Code as follows Private Sub SaveReportAsHtml(rdcFile As String, outputfolderRoot As String) 'rdcFile = = "Report001ByPhil" 'outputfolderRoot = = "C:\temp" Dim localReport As New LocalReport() localReport.ReportPath = rdcFile Dim ds As DataSet = FillADataSetWithSampleData() Dim reportDataSource As New ReportDataSource("DataSet1", ds.Tables("table1")) localReport.DataSources.Add(reportDataSource) Dim mimeType As String Dim encoding As String Dim extension As String Dim streamIds() As String Dim warnings() As Microsoft.Reporting.WebForms.Warning Dim outputFormat As String = "MHTML" 'does not work outputFormat = "HTML3.2" 'does not work outputFormat = "HTML4.0" 'does not work outputFormat = "HTMLOWC" 'does not work outputFormat = "PDF" 'works Dim bytes As Byte() = localReport.Render(outputFormat, Nothing, mimeType, encoding, extension, streamIds, warnings) Dim outputPath As String = Path.Combine(outputfolderRoot, "SSRS_output") outputPath = outputPath + "." + outputFormat DeleteFile(outputPath) Using fs As New FileStream(outputPath, FileMode.Create) fs.Write(bytes, 0, bytes.Length) End Using End Sub
-
The code below will load an rdl report from a datasource and save it as PDF. But only PDF. If I choose any other format it errors with System.ArgumentOutOfRangeException HResult=0x80131502 Message=Specified argument was out of the range of valid values. Parameter name: format Source=Microsoft.ReportViewer.WebForms ... at Microsoft.Reporting.WebForms.Report.Render(String format, String deviceInfo, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& --- I would welcome a suggestion. Code as follows Private Sub SaveReportAsHtml(rdcFile As String, outputfolderRoot As String) 'rdcFile = = "Report001ByPhil" 'outputfolderRoot = = "C:\temp" Dim localReport As New LocalReport() localReport.ReportPath = rdcFile Dim ds As DataSet = FillADataSetWithSampleData() Dim reportDataSource As New ReportDataSource("DataSet1", ds.Tables("table1")) localReport.DataSources.Add(reportDataSource) Dim mimeType As String Dim encoding As String Dim extension As String Dim streamIds() As String Dim warnings() As Microsoft.Reporting.WebForms.Warning Dim outputFormat As String = "MHTML" 'does not work outputFormat = "HTML3.2" 'does not work outputFormat = "HTML4.0" 'does not work outputFormat = "HTMLOWC" 'does not work outputFormat = "PDF" 'works Dim bytes As Byte() = localReport.Render(outputFormat, Nothing, mimeType, encoding, extension, streamIds, warnings) Dim outputPath As String = Path.Combine(outputfolderRoot, "SSRS_output") outputPath = outputPath + "." + outputFormat DeleteFile(outputPath) Using fs As New FileStream(outputPath, FileMode.Create) fs.Write(bytes, 0, bytes.Length) End Using End Sub
Google
visual basic "LocalReport" render "Specified argument was out of the range of valid values."
From that and this very site https://www.codeproject.com/Questions/1130614/How-to-render-localreport-to-HTML-using-csharp It says you can't do what you are attempting. I did not verify the answer.
-
The code below will load an rdl report from a datasource and save it as PDF. But only PDF. If I choose any other format it errors with System.ArgumentOutOfRangeException HResult=0x80131502 Message=Specified argument was out of the range of valid values. Parameter name: format Source=Microsoft.ReportViewer.WebForms ... at Microsoft.Reporting.WebForms.Report.Render(String format, String deviceInfo, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& --- I would welcome a suggestion. Code as follows Private Sub SaveReportAsHtml(rdcFile As String, outputfolderRoot As String) 'rdcFile = = "Report001ByPhil" 'outputfolderRoot = = "C:\temp" Dim localReport As New LocalReport() localReport.ReportPath = rdcFile Dim ds As DataSet = FillADataSetWithSampleData() Dim reportDataSource As New ReportDataSource("DataSet1", ds.Tables("table1")) localReport.DataSources.Add(reportDataSource) Dim mimeType As String Dim encoding As String Dim extension As String Dim streamIds() As String Dim warnings() As Microsoft.Reporting.WebForms.Warning Dim outputFormat As String = "MHTML" 'does not work outputFormat = "HTML3.2" 'does not work outputFormat = "HTML4.0" 'does not work outputFormat = "HTMLOWC" 'does not work outputFormat = "PDF" 'works Dim bytes As Byte() = localReport.Render(outputFormat, Nothing, mimeType, encoding, extension, streamIds, warnings) Dim outputPath As String = Path.Combine(outputfolderRoot, "SSRS_output") outputPath = outputPath + "." + outputFormat DeleteFile(outputPath) Using fs As New FileStream(outputPath, FileMode.Create) fs.Write(bytes, 0, bytes.Length) End Using End Sub
LocalReport.Render Method (String, String, CreateStreamCallback, out Warning ) (Microsoft.Reporting.WinForms) | Microsoft Learn[^]:
Supported formats include Excel, PDF, Word, and Image.
Note that this specifically does not mention HTML in any form. You can use the LocalReport.ListRenderingExtensions method[^] to get the list of supported formats.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Google
visual basic "LocalReport" render "Specified argument was out of the range of valid values."
From that and this very site https://www.codeproject.com/Questions/1130614/How-to-render-localreport-to-HTML-using-csharp It says you can't do what you are attempting. I did not verify the answer.
Thank you that was very helpful.
-
LocalReport.Render Method (String, String, CreateStreamCallback, out Warning ) (Microsoft.Reporting.WinForms) | Microsoft Learn[^]:
Supported formats include Excel, PDF, Word, and Image.
Note that this specifically does not mention HTML in any form. You can use the LocalReport.ListRenderingExtensions method[^] to get the list of supported formats.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Thank you. That was very helpful.