Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hello,
I have a Winform Application in which i have 2 separate rdlc's now on click of button i need generate the report with out reportViewer and to save the report as 2 separate .pdf files.

Any suggestions please!
Posted

sorry i cannot copy and paste code, but i have done this before, its very easy as far as i remember.

1.) Initialize ReportViewer
2.) Set the LocalReport-Path
3.) Use the Export to save it to disk

Code should be something along those lines:

C#
ReportViewer rv = new ReportViewer();
rv.LocalReport.ReportPath = @"resources\test.rdlc";
rv.RefreshReport();
File.WriteAllBytes(@"c:\my.pdf", rv.LocalReport.Render("PDF"));
 
Share this answer
 
v5
Comments
rohit24c 2-Aug-12 4:58am    
its show "An error occurred during local report processing". at 3rd line in your code.
Basically its a rdlc which has subreport and i am having dataset in that rdlc
efkah 2-Aug-12 5:45am    
Third Line? I would have expected second line, as i said, the lines are to be understood as pseudo-code;-)
try rv.Update() or rv.Show() in between the lines to force the data to be loaded (i editted my solution).
If this doesnt work, look up the Render-Method of the LocalReport:
http://msdn.microsoft.com/en-US/library/ms252172%28v=vs.80%29
I am sorry, i cant help you any further within the next probably 10 hours, and until then i will have forgotten you, so better not expect further help.
hi
Please try this


XML
<rsweb:ReportViewer ID="Report1" runat="server" Font-Names="Verdana" Font-Size="8pt"
    Height="515px" Width="100%" ShowExportControls="true" SizeToReportContent="False" >
    <LocalReport ReportPath="Rdlc\reports1.rdlc" EnableHyperlinks="True">
        <DataSources>
            <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="reports1_reports1" />
        </DataSources>
    </LocalReport>
</rsweb:ReportViewer>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData"
    TypeName="ReportTableAdapters."></asp:ObjectDataSource>


//Code behind

C#
ReportDataSource datasource = new
                   ReportDataSource("reports1_reports1",
             dtViewInfo);



              Report1.LocalReport.DataSources.Clear();
              Report1.LocalReport.DataSources.Add(datasource);
              Report1.LocalReport.Refresh();

              Report1.Visible = true;

For more ref:
http://beyondrelational.com/modules/24/syndicated/519/posts/12873/sql-server-develop-reports-with-rdlc-aspnet.aspx[^]
 
Share this answer
 
v3

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