Dear All,
I am doing an Online Examination project with ASP.Net with C# (Framework 3.5).And i am already deployed my application in IIS 5.1. My application has print result button at end of examination.The issue is,while giving print the report is printing on the machine where application deployed (ie, IIS machine). Is there any way that I can have this report print on the local machine?because huge number of students attending the exam same time and all machine have their own printer installed..
Please help,
Best regards,
Fuad
Loading
fuad pulpadanPosted May 7, 2013, 6:49 AM
protected void btnPrint_Click(object sender, EventArgs e)
{
try
{
PrintResult();
}
catch (Exception ex) { }
}
private void PrintResult()
{
LocalReport report = new LocalReport();
report.ReportPath = @"Report/rsPrintResult.rdlc";
report.DataSources.Add(new ReportDataSource("dsPrintResult_dtPrintResult", mydb.GetPrintData(Convert.ToInt32(Session["SessionID"].ToString()), Session["InstructorID"].ToString())));
Export(report);
Print();
}
private void Export(LocalReport report)
{
try
{
string deviceInfo = string deviceInfo = "
Warning[] warnings;
m_streams = new List();
report.Render("Image", deviceInfo, CreateStream, out warnings);
foreach (Stream stream in m_streams)
stream.Position = 0;
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
}
private void Print()
{
if (m_streams == null || m_streams.Count == 0)
throw new Exception("Error: no stream to print.");
PrintDocument printDoc = new PrintDocument();
if (!printDoc.PrinterSettings.IsValid)
{
throw new Exception("Error: cannot find the default printer.");
}
else
{
printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
m_currentPageIndex = 0;
printDoc.Print();
}
}
private void PrintPage(object sender, PrintPageEventArgs ev)
{
Metafile pageImage = new Metafile(m_streams[m_currentPageIndex]);
Rectangle adjustedRect = new Rectangle( ev.PageBounds.Left - (int)ev.PageSettings.HardMarginX, ev.PageBounds.Top - (int)ev.PageSettings.HardMarginY, ev.PageBounds.Width, ev.PageBounds.Height);
ev.Graphics.FillRectangle(Brushes.White, adjustedRect);
ev.Graphics.DrawImage(pageImage, adjustedRect);
m_currentPageIndex++;
ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
}
Ravi ShekharPosted May 7, 2013, 4:48 AM