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.Collecti ons.Generic;
using System.Windows. Forms;
using Microsoft.Repor ting.WinForms;
public class Demo : IDisposable
{
private int m_currentPageIn dex;
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.x ml");
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(st ring name,
string fileNameExtensi on, Encoding encoding,
string mimeType, bool willSeek)
{
Stream stream = new FileStream(@".. \..\" + name +
"." + fileNameExtensi on, FileMode.Create );
m_streams.Add(s tream);
return stream;
}
// Export the given report as an EMF (Enhanced Metafile) file.
private void Export(LocalRep ort report)
{
string deviceInfo =
"<DeviceInf o>" +
" <OutputFormat>E MF</OutputFormat>" +
" <PageWidth>8.5i n</PageWidth>" +
" <PageHeight>11i n</PageHeight>" +
" <MarginTop>0.25 in</MarginTop>" +
" <MarginLeft>0.2 5in</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(objec t sender, PrintPageEventA rgs ev)
{
Metafile pageImage = new
Metafile(m_stre ams[m_currentPageIn dex]);
ev.Graphics.Dra wImage(pageImag e, ev.PageBounds);
m_currentPageIn dex++;
ev.HasMorePages = (m_currentPageI ndex < 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.Printe rSettings.Print erName = printerName;
if (!printDoc.Prin terSettings.IsV alid)
{
string msg = String.Format(
"Can't find printer \"{0}\".", printerName);
MessageBox.Show (msg, "Print Error");
return;
}
printDoc.PrintP age += new PrintPageEventH andler(PrintPag e);
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.ReportPa th = @"..\..\Report. rdlc";
report.DataSour ces.Add(
new ReportDataSourc e("Sales", LoadSalesData() ));
Export(report);
m_currentPageIn dex = 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
0 4243 Sign in to post your reply or Sign up for a free account.
Similar topics |
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 really want to have a
hardcopy.
The customer selects the records with a special selection form, where
he can combine up to appr. 20 different criterias, which are combined
to a more or less complex filter string. This string is then written
to the...
|
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 file...whatever.
I described my situation to the guy I'm doing work for and he did some
research for me and came up with the following link.
http://www.novapdf.com/
The part that should excite us Access developers is their SDK
|
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 reporting
needs. I was wondering if anybody has an opinion on how the new
reportViewer control works in comparison to Crystal. One of the main
problems I have been having with Crystal Reports is that they seem to
load very slow no matter how small the...
|
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 report directly
to the printer bypassing the Crystal report viewer altogether.
When sending the job directly to the printer I use the PrintToPrinter
command
CR.PrintToPrinter(1, False, 0, 0)
|
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 am working by using VS2005 and dotNet Framework 2.0. I have an ASP Content page, with one ReportViewer, and 5 RDLC files. This page contains a dropdownlist with 5 items, which if someone choose any one of them, they will see the report on the bottom...
| |
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 Report control. My problem is
in rendering the report from the rdlc file for printing to a line printer.
Following the example from MSDN Help at
http://msdn2.microsoft.com/en-us/library/ms252172(VS.80).aspx
I can print the rdlc report...
|
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 on the report server. See the error log for more
details.
Do I have something configured wrong? I do not knw where to find the error
log to review it.
|
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 elements: lines, borders, "labels", etc..) and another one for printing - it needs only the information from the dataset.
I need this because i have a lot of "official" documents (medication prescriptions, sick leave etc...) so the user must see the...
|
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 able to print, but now I need to
print it directly without any preview.
I have found some articles, but this dont work and they are quite
complicated (for me ... :-))
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |