Dear Sir,
I have an error Second Code after modification code `A generic error occurred in GDI+ in render Rdlc with VB.NET`
Please Guide
Thanks
First Code
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
' Determine the correct rendering format and file extension
Select Case format.ToUpper()
Case "PDF"
bytes = ReportViewer1.LocalReport.Render(
"PDF", "<DeviceInfo><OutputFormat>PDF</OutputFormat>
</DeviceInfo>",
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 Else
MessageBox.Show("Unsupported format.")
Exit Sub
End Select
Dim filePath As String = String.Format("{0}\ExportedBusinessCard{1}.{2}", folderPath, DateTime.Now.Millisecond, extension)
File.WriteAllBytes(filePath, bytes)
Process.Start(filePath)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ComboBox1.SelectedIndex = 0
ReportViewer1.ProcessingMode = ProcessingMode.Local
'' Get the selected path
Dim selectedPath As String = ComboBox1.SelectedItem?.ToString()
ReportViewer1.LocalReport.ReportPath = selectedPath
Me.ReportViewer1.RefreshReport()
End Sub
Private Sub AmmaImageButton1_Click(sender As Object, e As EventArgs) Handles AmmaImageButton1.Click
ExportReport("PNG")
'ExportReport("PDF")
End Sub
Second Code
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
' Determine the correct rendering format and file extension
Select Case format.ToUpper()
Case "PDF"
bytes = ReportViewer1.LocalReport.Render(
"PDF", "<DeviceInfo><OutputFormat>PDF</OutputFormat>
</DeviceInfo>",
mimeType, encoding, extension, streamIds, warnings)
extension = "pdf"
Case "PNG"
bytes = ReportViewer1.LocalReport.Render(
"Image", "<DeviceInfo><OutputFormat>PNG</OutputFormat>
<DpiX>300</DpiX> <DpiY>300</DpiY> <PrintDpiX>300</PrintDpiX> <PrintDpiY>300</PrintDpiY>
</DeviceInfo>",
mimeType, encoding, extension, streamIds, warnings)
extension = "png"
Dim TempFileRSGeneratedTIFF As String = folderPath & "TEST.PNG"
' Save png file returned by RS
Using stream As FileStream = File.OpenWrite(TempFileRSGeneratedTIFF)
stream.Write(bytes, 0, bytes.Length)
End Using
' Read png file into bitmap
Dim image As New Bitmap(TempFileRSGeneratedTIFF)
' Change the resolution to what it was supposed to be in the first place..
image.SetResolution(300, 300)
' Save the final version of the file
`Error below line code A generic error occurred in GDI+`
image.Save(folderPath, System.Drawing.Imaging.ImageFormat.Png)
image.Dispose()
Case Else
MessageBox.Show("Unsupported format.")
Exit Sub
End Select
Dim filePath As String = String.Format("{0}\ExportedBusinessCard{1}.{2}", folderPath, DateTime.Now.Millisecond, extension)
File.WriteAllBytes(filePath, bytes)
Process.Start(filePath)
End Sub