Mani Pazhana
asked on
Printing with ASP.Net hosted on IIS 7.0
Hello Experts,
I am using ASP.NET /VB.Net web application.
I am trying to print the report, it work locally when tested from visual studio 2010... but not from the Server when deployed to IIS.
I tried different options, it is not finding the printer when the application deployed to IIS on the Network server...
here is some snippet I used with no luck...
Private Function DefaultPrinterName() As String
Dim settings As Drawing.Printing.PrinterSe ttings = New Drawing.Printing.PrinterSe ttings()
Return settings.PrinterName
End Function
Private Sub Print()
If m_streams Is Nothing OrElse m_streams.Count = 0 Then
Throw New Exception("Error: no stream to print.")
End If
Dim printDoc As New PrintDocument()
printDoc.PrinterSettings.P rinterName = DefaultPrinterName()
AddHandler printDoc.PrintPage, AddressOf PrintPage
m_currentPageIndex = 0
printDoc.Print()
End Sub
any idea?
Thanks
I am using ASP.NET /VB.Net web application.
I am trying to print the report, it work locally when tested from visual studio 2010... but not from the Server when deployed to IIS.
I tried different options, it is not finding the printer when the application deployed to IIS on the Network server...
here is some snippet I used with no luck...
Private Function DefaultPrinterName() As String
Dim settings As Drawing.Printing.PrinterSe
Return settings.PrinterName
End Function
Private Sub Print()
If m_streams Is Nothing OrElse m_streams.Count = 0 Then
Throw New Exception("Error: no stream to print.")
End If
Dim printDoc As New PrintDocument()
printDoc.PrinterSettings.P
AddHandler printDoc.PrintPage, AddressOf PrintPage
m_currentPageIndex = 0
printDoc.Print()
End Sub
any idea?
Thanks
the code is running on the server, so it is only able to access printer defined on the server.
thats why most apps provide a 'preview' open that the user prints locally.
thats why most apps provide a 'preview' open that the user prints locally.
ASKER
i am seeing the network printer installed on the server.
When I logged in , the print function work. If I am not logged in to the server , it is not working
Any idea?
Thanks
When I logged in , the print function work. If I am not logged in to the server , it is not working
Any idea?
Thanks
ASKER
I need a sample code(VB.Net/ASP.Net) that will print the report in batch..i need to print multiple reports...
Its not a report is it? You are printing rendering text yourself into printer driver. That is more suitable for a windows based application rather than a web application. Have you considered using a report component like crystal reports?
ASKER
I am having a report build like this:
Not able to print when I access the report outside the server. it prints locally and also when I logged into the server...but not outside the server...
Public Sub PrintReport(ByVal reqId As Integer)
Dim printObject As New PrintObject
Dim report As New Microsoft.Reporting.WebFor ms.LocalRe port()
Dim item As Requisition = RequisitionManager.getReqb yReqid(req Id)
Try
If item.Revised Then
report.ReportPath = "ReqReportRevised.rdlc"
Else
report.ReportPath = "ReqReport.rdlc"
End If
report.DataSources.Add(New Microsoft.Reporting.WebFor ms.ReportD ataSource( "DataSet1_ getPartLis t", printObject.GetPartListRep ort(reqId) ))
report.DataSources.Add(New Microsoft.Reporting.WebFor ms.ReportD ataSource( "DataSet1_ getReqbyRe qid", printObject.GetReqbyReqId( reqId)))
Export(report)
Catch ex As Exception
Throw (ex)
Finally
item = Nothing
report = Nothing
End Try
End Sub
Not able to print when I access the report outside the server. it prints locally and also when I logged into the server...but not outside the server...
Public Sub PrintReport(ByVal reqId As Integer)
Dim printObject As New PrintObject
Dim report As New Microsoft.Reporting.WebFor
Dim item As Requisition = RequisitionManager.getReqb
Try
If item.Revised Then
report.ReportPath = "ReqReportRevised.rdlc"
Else
report.ReportPath = "ReqReport.rdlc"
End If
report.DataSources.Add(New
report.DataSources.Add(New
Export(report)
Catch ex As Exception
Throw (ex)
Finally
item = Nothing
report = Nothing
End Try
End Sub
ASKER
remaning code:
Private Sub Export(ByVal report As Microsoft.Reporting.WebFor ms.LocalRe port)
Dim warnings As Microsoft.Reporting.WebFor ms.Warning () = Nothing
Dim streamids() As String = Nothing
Dim mimeType As String = String.Empty
Dim encoding As String = String.Empty
Dim extension As String = String.Empty
Dim _r As Random = New Random
Dim uniqueNumber As String = _r.Next().ToString()
Dim bytes() As Byte = report.Render("PDF", Nothing, mimeType, encoding, extension, streamids, warnings)
Dim fs As FileStream = New FileStream(HttpContext.Cur rent.Serve r.MapPath( "Output_" + uniqueNumber + ".pdf"), FileMode.Create)
fs.Write(bytes, 0, bytes.Length)
fs.Close()
Dim document As iTextSharp.text.Document = New iTextSharp.text.Document(i TextSharp. text.PageS ize.LETTER )
Dim reader As iTextSharp.text.pdf.PdfRea der = New iTextSharp.text.pdf.PdfRea der(HttpCo ntext.Curr ent.Server .MapPath(" Output_" + uniqueNumber + ".pdf"))
PrintPDFfiles(HttpContext. Current.Se rver.MapPa th("Output _" + uniqueNumber + ".pdf"))
document.Close()
document = Nothing
reader.Close()
reader = Nothing
FileCleanUpOnServer(HttpCo ntext.Curr ent.Server .MapPath(" Output_" + uniqueNumber + ".pdf"))
End Sub
Private Sub PrintPDFfiles(ByVal fileName As String)
Dim p As New Process()
p.StartInfo = New ProcessStartInfo() With {.CreateNoWindow = True, .Verb = "print", .FileName = fileName}
p.Start()
p.WaitForInputIdle()
p.CloseMainWindow()
p.Kill()
End Sub
Private Sub Export(ByVal report As Microsoft.Reporting.WebFor
Dim warnings As Microsoft.Reporting.WebFor
Dim streamids() As String = Nothing
Dim mimeType As String = String.Empty
Dim encoding As String = String.Empty
Dim extension As String = String.Empty
Dim _r As Random = New Random
Dim uniqueNumber As String = _r.Next().ToString()
Dim bytes() As Byte = report.Render("PDF", Nothing, mimeType, encoding, extension, streamids, warnings)
Dim fs As FileStream = New FileStream(HttpContext.Cur
fs.Write(bytes, 0, bytes.Length)
fs.Close()
Dim document As iTextSharp.text.Document = New iTextSharp.text.Document(i
Dim reader As iTextSharp.text.pdf.PdfRea
PrintPDFfiles(HttpContext.
document.Close()
document = Nothing
reader.Close()
reader = Nothing
FileCleanUpOnServer(HttpCo
End Sub
Private Sub PrintPDFfiles(ByVal fileName As String)
Dim p As New Process()
p.StartInfo = New ProcessStartInfo() With {.CreateNoWindow = True, .Verb = "print", .FileName = fileName}
p.Start()
p.WaitForInputIdle()
p.CloseMainWindow()
p.Kill()
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
--------------------------
Here is error I see from event log on the server:
Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 3/25/2015 12:28:08 PM
Event time (UTC): 3/25/2015 5:28:08 PM
Event ID: aabdefc27938450d876f3271cd
Event sequence: 42
Event occurrence: 1
Event detail code: 0
Application information:
Application domain: /LM/W3SVC/2/ROOT-3-1307177
Trust level: Full
Application Virtual Path: /
Application Path: C:\ReqTracker\
Machine name: CPSTAGING
Process information:
Process ID: 4416
Process name: w3wp.exe
Account name: IIS APPPOOL\ReqTrackerStaging
Exception information:
Exception type: InvalidPrinterException
Exception message: No printers are installed.
at PrintObject.PrintReport(In
at Requisitions.btnBatchPrint
at System.Web.UI.WebControls.
at System.Web.UI.WebControls.
at System.Web.UI.WebControls.
at System.Web.UI.Page.RaisePo
at System.Web.UI.Page.RaisePo
at System.Web.UI.Page.Process