I am trying to print RDLC Report but I am getting error below
Server Error in '/SulaSignar' Application.
The process cannot access the file 'C:\inetpub\wwwroot\SulaSignar\Files\Recieptdata_0.EMF' because it is being used by another process.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.IOException: The process cannot access the file 'C:\inetpub\wwwroot\SulaSignar\Files\Recieptdata_0.EMF' because it is being used by another process.
Source Error:
here is my code
Protected Overloads Sub Print(ByVal sender As Object, ByVal e As EventArgs)
Export(ReportViewer1.LocalReport)
pageIndex = 0
Print()
End Sub
Private Sub Export(ByVal report As LocalReport)
Dim deviceInfo As String = "<DeviceInfo>" +
" <OutputFormat>EMF</OutputFormat>" +
" <PageWidth>8.5in</PageWidth>" +
" <PageHeight>11in</PageHeight>" +
" <MarginTop>0.25in</MarginTop>" +
" <MarginLeft>0.25in</MarginLeft>" +
" <MarginRight>0.25in</MarginRight>" +
" <MarginBottom>0.25in</MarginBottom>" +
"</DeviceInfo>"
Dim warnings() As Warning
streams = New List(Of Stream)
report.Render("Image", deviceInfo, AddressOf CreateStream, warnings)
For Each stream As Stream In streams
stream.Position = 0
Next
End Sub
Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Export(ReportViewer1.LocalReport)
pageIndex = 0
Print()
End Sub
Private Function CreateStream(ByVal name As String, ByVal fileNameExtension As String, ByVal encoding As Encoding, ByVal mimeType As String, ByVal willSeek As Boolean) As Stream
Dim stream As Stream = New FileStream((Server.MapPath("~/Files/") _
+ (name + ("." + fileNameExtension))), FileMode.Create)
streams.Add(stream)
Return stream
End Function
Private Sub PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
Dim pageImage As Metafile = New Metafile(streams(pageIndex))
ev.Graphics.DrawImage(pageImage, ev.PageBounds)
pageIndex = (pageIndex + 1)
ev.HasMorePages = (pageIndex < streams.Count)
End Sub
Private Overloads Sub Print()
If ((streams Is Nothing) _
OrElse (streams.Count = 0)) Then
Return
End If
Dim printDoc As PrintDocument = New PrintDocument
AddHandler printDoc.PrintPage, AddressOf Me.PrintPage
printDoc.Print()
End Sub
Protected Sub Export(ByVal sender As Object, ByVal e As EventArgs)
Dim warnings As Warning()
Dim streamIds As String()
Dim contentType As String
Dim encoding As String
Dim extension As String
'Export the RDLC Report to Byte Array.
Dim bytes As Byte() = ReportViewer1.LocalReport.Render(rbFormat.SelectedItem.Value, Nothing, contentType, encoding, extension, streamIds, warnings)
'Download the RDLC Report in Word, Excel, PDF and Image formats.
Response.Clear()
Response.Buffer = True
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = contentType
Response.AppendHeader("Content-Disposition", "attachment; filename=RDLC." & extension)
Response.BinaryWrite(bytes)
Response.Flush()
Response.End()
End Sub
thanks in advance