Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0 Reports WinForm
Hi,
 
I have a requirement to export the data(which is having the 1000 rows) into PDF file automatically. We are not supposed to use third party tools like iTextSharp. So I used the Microsoft.Office.Interop.Word dll to generate the PDF files but it is taking more than 9 mins to export 1000 rows of data.
 
I preferred to use Microsoft.Reporting.WinForms. Created Dataset, Designed the Report, and wrote the code but when I am going to render the data to localreport I am getting the exception "An error occurred during local report processing." at this line of code
 

byte[] bytes = rv.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings);
 
Here is my complete code plz look into this.
 
 LocalReport lr = new LocalReport();
                ReportViewer rv = new ReportViewer();
                
                DataSet1 expo = new DataSet1();
                ReportDataSource rds = new ReportDataSource();
                expo.Merge(fDS);
                rds.Name = "dataPointDS";
                rds.Value = expo.Tables["dataPointDS"];
                rv.LocalReport.DataSources.Clear();
                rv.ProcessingMode = ProcessingMode.Local;
                rv.LocalReport.ReportEmbeddedResource = rPath;
                rv.LocalReport.DataSources.Add(rds);
                rv.RefreshReport();
Warning[] warnings;
                string[] streamids;
                string mimeType = string.Empty;
                string encoding = string.Empty;
                string extension = string.Empty;
byte[] bytes = rv.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings);
                        FileStream fs = new FileStream(XLPath + "\\" + fileName.Replace("/", "_") + ".pdf", FileMode.Create, FileAccess.Write);
                        fs.Write(bytes, 0, bytes.Length);
                        fs.Close(); 
 

When I use reportviewer control on my windows form, it is showing the data. But when I wrote the code to process locally I am getting this exception.
 
Can some body help on this.
 
Thanks in advance
Murali.
Posted 18-Dec-12 2:17am
Edited 17-Mar-14 19:15pm
v4
Comments
Stephen Hewison at 18-Dec-12 7:23am
   
That's just a generic top level error. Is there an inner exception?
Murali Krishna Babu at 19-Dec-12 0:20am
   
Hi Stephan,
Thanks for your reply, there are no inner exceptions. Here is my code plz look into this.
 
LocalReport lr = new LocalReport();
ReportViewer rv = new ReportViewer();

DataSet1 expo = new DataSet1();
ReportDataSource rds = new ReportDataSource();
expo.Merge(fDS);
rds.Name = "dataPointDS";
rds.Value = expo.Tables["dataPointDS"];
rv.LocalReport.DataSources.Clear();
rv.ProcessingMode = ProcessingMode.Local;
rv.LocalReport.ReportEmbeddedResource = rPath;
rv.LocalReport.DataSources.Add(rds);
rv.RefreshReport();
Warning[] warnings;
string[] streamids;
string mimeType = string.Empty;
string encoding = string.Empty;
string extension = string.Empty;
byte[] bytes = rv.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings);
FileStream fs = new FileStream(XLPath + "\\" + fileName.Replace("/", "_") + ".pdf", FileMode.Create, FileAccess.Write);
fs.Write(bytes, 0, bytes.Length);
fs.Close();
 
Thanks
Murali
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Found the solution for it.
 
For windows applications we have to provide the rdlc path using the streams then only report viewer recognize it.
 
Have to load the rdlc using stream rather than
rv.LocalReport.ReportEmbeddedResource = rPath;
 
Here is the working code
 
                LocalReport lr = new LocalReport();
                ReportViewer rv = new ReportViewer();
                DataSet1 expo = new DataSet1();
                ReportDataSource rds = new ReportDataSource();
                expo.Merge(fDS);
                rds.Name = "DataSet1";
                rds.Value = expo.Tables["dataPointDS"];
                rv.LocalReport.DataSources.Clear();
                rv.ProcessingMode = ProcessingMode.Local;                             
                using (StreamReader rdlcSR = new StreamReader(rPath))
                {
                    rv.LocalReport.LoadReportDefinition(rdlcSR);
                    rv.LocalReport.Refresh();
                }
                rv.LocalReport.DataSources.Add(rds);                           
 
                Warning[] warnings;
                string[] streamids;
                string mimeType = string.Empty;
                string encoding = string.Empty;
                string extension = string.Empty;
                byte[] bytes = rv.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension,  out streamids, out warnings);
                FileStream fs = new FileStream(XLPath + "\\" + fileName.Replace("/", "_") + ".pdf", FileMode.Create, FileAccess.Write);
                fs.Write(bytes, 0, bytes.Length);
                fs.Close();
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

EXCELLENT SAMPLE! HELPED ME A LOT!
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Need Help...Can we render html from report viewer..please reply as soon as possible.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 6,803
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,421
3 Manas Bhardwaj 4,841
4 Maciej Los 4,330


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 18 Apr 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100