Click here to Skip to main content
15,890,336 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
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.

C#
 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
Updated 17-Mar-14 18:15pm
v4
Comments
Stephen Hewison 18-Dec-12 7:23am    
That's just a generic top level error. Is there an inner exception?
Murali Krishna Babu 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

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
XML
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();
 
Share this answer
 
EXCELLENT SAMPLE! HELPED ME A LOT!
 
Share this answer
 
Need Help...Can we render html from report viewer..please reply as soon as possible.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900