Dear Sir,
I'm Trying the export images with RDLC not stored on the hard disk with vb.net in winform
File is not saved according to the savefiledialog. File is not exporting to the specified path.
Is there something wrong with my code?
Please guide me
Thanks
Imports System.IO
Imports System.Runtime.InteropServices
Imports Microsoft.Reporting.WinForms
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.ReportViewer1.RefreshReport()
End Sub
Public Sub ExportReport(format As String)
Dim bytes As Byte()
Dim mimeType As String = ""
Dim encoding As String = ""
Dim extension As String = ""
Dim streamIds As String() = Nothing
Dim warnings As Warning() = Nothing
ReportViewer1.ProcessingMode = ProcessingMode.Local
ReportViewer1.LocalReport.ReportPath = "BusinessCardReport.rdlc"
' Determine the correct rendering format and file extension
Select Case format.ToUpper()
Case "PDF"
bytes = ReportViewer1.LocalReport.Render(
"PDF", Nothing, mimeType, encoding, extension, streamIds, warnings)
extension = "pdf"
Case "PNG"
bytes = ReportViewer1.LocalReport.Render(
"Image", "<DeviceInfo><OutputFormat>PNG</OutputFormat></DeviceInfo>",
mimeType, encoding, extension, streamIds, warnings)
extension = "png"
Case "JPG"
bytes = ReportViewer1.LocalReport.Render(
"Image", "<DeviceInfo><OutputFormat>JPEG</OutputFormat></DeviceInfo>",
mimeType, encoding, extension, streamIds, warnings)
extension = "jpg"
Case Else
MessageBox.Show("Unsupported format.")
Exit Sub
End Select
SaveFileDialog1.DefaultExt = format
SaveFileDialog1.Filter = "All files (*.*)|*.*"
' Save to a file
Dim filePath As String = $"ExportedBusinessCard{DateTime.Now.Date.Millisecond}.{extension}"
If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
System.IO.File.WriteAllBytes(filePath, bytes)
End If
'// File.WriteAllBytes(filePath, bytes)
MessageBox.Show($"Business card exported to {filePath}")
End Sub
Private Sub btnexport_Click(sender As Object, e As EventArgs) Handles btnexport.Click
ExportReport("PNG")
End Sub
End Class