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.PrinterSettings = New Drawing.Printing.PrinterSettings()
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.PrinterName = DefaultPrinterName()
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(Int32 reqId)
at Requisitions.btnBatchPrint_Click(Object sender, EventArgs e)
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Robberbaron (robr)
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.
Mani Pazhana
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
I need a sample code(VB.Net/ASP.Net) that will print the report in batch..i need to print multiple reports...
Nasir Razzaq
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?
Mani Pazhana
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.WebForms.LocalReport()
Dim item As Requisition = RequisitionManager.getReqbyReqid(reqId)
Try
If item.Revised Then
report.ReportPath = "ReqReportRevised.rdlc"
Else
report.ReportPath = "ReqReport.rdlc"
End If
report.DataSources.Add(New Microsoft.Reporting.WebForms.ReportDataSource("DataSet1_getPartList", printObject.GetPartListReport(reqId)))
report.DataSources.Add(New Microsoft.Reporting.WebForms.ReportDataSource("DataSet1_getReqbyReqid", printObject.GetReqbyReqId(reqId)))
Export(report)
Catch ex As Exception
Throw (ex)
Finally
item = Nothing
report = Nothing
End Try
Private Sub Export(ByVal report As Microsoft.Reporting.WebForms.LocalReport)
Dim warnings As Microsoft.Reporting.WebForms.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.Current.Server.MapPath("Output_" + uniqueNumber + ".pdf"), FileMode.Create)
fs.Write(bytes, 0, bytes.Length)
fs.Close()
Dim document As iTextSharp.text.Document = New iTextSharp.text.Document(iTextSharp.text.PageSize.LETTER)
Dim reader As iTextSharp.text.pdf.PdfReader = New iTextSharp.text.pdf.PdfReader(HttpContext.Current.Server.MapPath("Output_" + uniqueNumber + ".pdf"))
PrintPDFfiles(HttpContext.Current.Server.MapPath("Output_" + uniqueNumber + ".pdf"))
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
--------------------------
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