Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
|
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 13th, 2011, 02:36 AM
Registered User
 
Join Date: May 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem With Direct Printing from Microsoft Report Viewer.

Hi All,

I am trying to print a Report viewer content (Report .rdlc file) in C#.

The Algo is given below:-
1. After generation of Report, I am making the Report content as an Image extention is .emf.
2. Saveing the report into D://Report/Voucher.emf
3. Calling Print Function.

When I an running this algo from Code then it is working properly. Saveing the Image in proper path and Printing properly.

But when I am makeing the WebSetup and Insatalling this webApplicatiion and running from IIS 6.0 then it is Generating the Image in .emf format but not printing at all.

Can any one help me in this situation.

If you know please help me.

*********************Please See the Code Below**************************

protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
LocalReport lr = ReportViewer1.LocalReport;
Export(lr);
m_currentPageIndex = 0;
Print();
Dispose();
string Path = Session["Path"].ToString();
}
#region Deviceinfo
// Export the given report as an EMF (Enhanced Metafile) file.

private void Export(LocalReport report)
{
string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>emf</OutputFormat>" +
" <PageWidth>8.3in</PageWidth>" +
" <PageHeight>5.0in</PageHeight>" +
" <MarginTop>0.2in</MarginTop>" +
" <MarginLeft>0.2in</MarginLeft>" +
" <MarginRight>0.0in</MarginRight>" +
" <MarginBottom>0.0in</MarginBottom>" +
"</DeviceInfo>";
Warning[] warnings;
m_streams = new List<Stream>();

report.Render("Image", deviceInfo, CreateStream, out warnings);

foreach (Stream stream in m_streams)
stream.Position = 0;
}
#endregion

#region PrintPageEvents
// Handler for PrintPageEvents
private void PrintPage(object sender, PrintPageEventArgs ev)
{//
Metafile pageImage = new Metafile(m_streams[m_currentPageIndex]);
ev.Graphics.DrawImage(pageImage, ev.PageBounds);
m_currentPageIndex++;
ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
}
#endregion
private Stream CreateStream(string name, string fileNameExtension, Encoding encoding, string mimeType, bool willSeek)
{


Stream stream = new FileStream("D:\\Report\\" + name + "." + fileNameExtension, FileMode.Create);

string path = "D:\\Report\\" + name + "." + emf";
Session["Path"] = "http://192.168.0.3/"+path; // This path will use to delete the image file after printing.

m_streams.Add(stream);
return stream;
}

#region Print function
private void Print()
{
System.Drawing.Printing.PrinterSettings oPS = new System.Drawing.Printing.PrinterSettings();
//string printerName=

string printerName = oPS.PrinterName;
if (m_streams == null || m_streams.Count == 0)
return;
PrintDocument printDoc = new PrintDocument();
System.Drawing.Printing.PrinterSettings pseting = new PrinterSettings();
printDoc.PrinterSettings.PrinterName = printerName;
PrintingPermission perm = new PrintingPermission(System.Security.Permissions.Per missionState.Unrestricted);
perm.Level = PrintingPermissionLevel.AllPrinting;
if (printerName != "")
{

printDoc.PrinterSettings.PrinterName = String.Format("{0}", printerName);
}
if (printDoc.PrinterSettings.IsValid != false)
{
printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
printDoc.Print();
}
}
#endregion

#region Dispose the Streem
public void Dispose()
{
if (m_streams != null)
{
foreach (Stream stream in m_streams)
stream.Close();
m_streams = null;
}



}
#endregion

#region Delete Image File
public static void Delete(string path)
{
File.Delete(path);
//Console.WriteLine("{0} was successfully deleted.", path);
}
#endregion

With Regards

Somesh Chatterjee

Last edited by someshchat; September 13th, 2011 at 02:49 AM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with PAGING for Report Viewer Somesh Reporting Services 0 April 30th, 2008 06:01 AM
Problem with crystal activex report viewer NagarajuK Crystal Reports 1 March 17th, 2008 06:57 PM
Problem with Paging in Report Viewer Probleminfinity ASP.NET 3.5 Professionals 0 November 12th, 2007 12:11 PM
print direct not viewer raheem Crystal Reports 0 June 25th, 2006 08:33 AM
Crystal Report (9) Viewer Problem Kaustav VB Components 1 October 30th, 2005 07:02 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.