473,387 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

sending a .rdlc report to printer directly without viewing it.

Hello Friends i m stuck up to a place wherein i want to print a report which is displaying on a reportviewer.

I actually want to send the report to printer directly without viewing it.

i am using a code for the same which i m posting here. I am getting an error on the line wherein i m rendering the report.

the error is " a window handle is not created for the control"

My code is :


using System;
using System.IO;
using System.Data;
using System.Text;
using System.Drawing.Imaging;
using System.Drawing.Printing;
using System.Collections.Generic;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;

public class Demo : IDisposable
{
private int m_currentPageIndex;
private IList<Stream> m_streams;

private DataTable LoadSalesData()
{
// Create a new DataSet and read sales data file
// data.xml into the first DataTable.
DataSet dataSet = new DataSet();
dataSet.ReadXml(@"..\..\data.xml");
return dataSet.Tables[0];
}
// Routine to provide to the report renderer, in order to
// save an image for each page of the report.
private Stream CreateStream(string name,
string fileNameExtension, Encoding encoding,
string mimeType, bool willSeek)
{
Stream stream = new FileStream(@"..\..\" + name +
"." + fileNameExtension, FileMode.Create);
m_streams.Add(stream);
return stream;
}
// Export the given report as an EMF (Enhanced Metafile) file.
private void Export(LocalReport report)
{
string deviceInfo =
"<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>";
Warning[] warnings;
m_streams = new List<Stream>();
report.Render("Image", deviceInfo, CreateStream, out warnings); foreach (Stream stream in m_streams)
stream.Position = 0;
}
// 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);
}

private void Print()
{
const string printerName =
"Microsoft Office Document Image Writer";
if (m_streams == null || m_streams.Count == 0)
return;
PrintDocument printDoc = new PrintDocument();
printDoc.PrinterSettings.PrinterName = printerName;
if (!printDoc.PrinterSettings.IsValid)
{
string msg = String.Format(
"Can't find printer \"{0}\".", printerName);
MessageBox.Show(msg, "Print Error");
return;
}
printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
printDoc.Print();
}
// Create a local report for Report.rdlc, load the data,
// export the report to an .emf file, and print it.
private void Run()
{
LocalReport report = new LocalReport();
report.ReportPath = @"..\..\Report.rdlc";
report.DataSources.Add(
new ReportDataSource("Sales", LoadSalesData()));
Export(report);
m_currentPageIndex = 0;
Print();
}

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

}



the code in bold is the place i am getting error ......please help me please i m badly stuck..

Thanks
Oct 10 '08 #1
0 4110

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Wolfgang | last post by:
Hi, I need to timestamp printed records with the printing date. According to the customer's requests the report must be opened in preview-mode and the user clicks on the printer button if he...
13
by: salad | last post by:
Hi Guys: I was stuck. I needed to send a report to a file. My beautiful report(s) in Access were going to require loss of formatting with RTFs, a PITA in WordMailMerge, sending it as a text...
9
by: Altman | last post by:
I am currently using ASP.Net 2003 and will be upgrading to 2005 sometime in the near future. I have been having issues with using Crystal Reports that were included with .Net to handle my...
0
by: John Smith | last post by:
Hello, I am developing a VB.NET 2003 application that will use lots of Crystal Reports. Sometimes the users will preview a report in a Crystal report viewer, and sometimes they will send the...
1
by: beebob | last post by:
Hi all, I am sorry if I have posted this problem to irrelevant forum. I am working in C#, and I don't find any C# forum here. I hope someone here can help me to resolve my problem. Here is: I...
2
by: =?Utf-8?B?UmljaA==?= | last post by:
On my development machine where I have Visual Studio 2005 loaded, I have an app that uses the Report control. I can view data in report format with the Report control -- the data renders OK in the...
18
by: =?Utf-8?B?SGVyYg==?= | last post by:
I'm using a ReportViewer in ASP.NET. From the development environment it works fine. When published and I try to open the page with the ReportViewer I get the error: An internal error occurred...
0
by: Deceneu | last post by:
Hi everyone, this is my first post so please bear with me. I have the following situation: i have a local report that needs to have two "versions": one for viewing in the report viewer (with all...
0
by: =?Utf-8?B?RnJhbmsgVXJheQ==?= | last post by:
Hi all I have problems printing a .rdlc report directly to the printer. I have created such a report without Datasource, I just fill some parameters in this report. With the ReportViewer I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.