I created a report with subreport in Standalone Report Designer. I want to export it to PDF programmatically. I created an example Windows Form Application which gets parameters from user with textboxes. And when user writes values to its indicated textbox and then presses export to pdf. Then my application export it to pdf. But I have something wrong there. I must get the datasource or connection from my report file in order to set it in the program. How can I do this ?
I will share my app's picture.
Here is my code :
01. private void BtnExportPDF_Click(object sender, EventArgs e)02. {03. var reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();04. 05. // set any deviceInfo settings if necessary06. var deviceInfo = new System.Collections.Hashtable();07. 08. 09. 10. // -2-11. // ***Declarative (TRDP/TRDX) report definitions***12. var reportSource = new UriReportSource();13. 14. // reportName is the path to the TRDP/TRDX file15. reportSource.Uri = @"C:\Users\OE\Desktop\TelerikReport\Deneme.trdp";16. //var reportPackager = new ReportPackager();17. //using (var sourceStream = System.IO.File.OpenRead(@"C:\Users\OE\Desktop\TelerikReport\Deneme.trdp"))18. //{19. // var report = (Report)reportPackager.UnpackageDocument(sourceStream);20. //}21. //Telerik.Reporting.SqlDataSource sqlDataSource = new Telerik.Reporting.SqlDataSource();22. //sqlDataSource.ProviderName = "System.Data.SqlClient";23. //sqlDataSource.ConnectionString = "Data Source=(local)\\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=True";24. 25. 26. // -2-27. 28. // -3-29. // ***Instance of the report definition***30. //var reportSource = new Telerik.Reporting.InstanceReportSource();31. 32. // Report1 is the class of the report. It should inherit Telerik.Reporting.Report class33. //reportSource.ReportDocument = new Report1();34. // -3-35. object parameterValue = txtBasDep.Text;36. reportSource.Parameters.Add("basdepid", parameterValue);37. object parameterValue1 = txtBitDep.Text;38. reportSource.Parameters.Add("bitdepid", parameterValue1);39. object parameterValue2 = txtSonDogum.Text;40. reportSource.Parameters.Add("sondogumtar", parameterValue2);41. 42. Telerik.Reporting.Processing.RenderingResult result = reportProcessor.RenderReport("PDF", reportSource, deviceInfo);43. 44. // Pass parameter value with the Report Source if necessary45. 46. 47. string fileName = result.DocumentName + "." + result.Extension;48. string path = @"C:\Users\OE\Desktop\TelerikReport";49. string filePath = System.IO.Path.Combine(path, fileName);50. 51. using (System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Create))52. {53. fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);54. }55. 56. MessageBox.Show("The report has been exported!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);57. }58.}