rdlc report without preview not working in setup file

Aug 9 2020 12:56 PM
i try to without preview print bill but visual studio in working fine but when to crate setup then that time rdlc not working sowing below error code so please help me
 
Error code
 
Microsoft.Reporting.WinForms.LocalProcessingException: An error occurred during local report processing. ---> System.ApplicationException: The report definition for report 'Report1' has not been specified ---> System.IO.FileNotFoundException: Could not find file 'C:\Program Files (x86)\Default Company Name\Setup1\Report1.rdlc'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at Microsoft.ReportingServices.StandalonePreviewStore.GetReportDefinition(PreviewItemContext itemContext)
--- End of inner exception stack trace ---
at Microsoft.ReportingServices.StandalonePreviewStore.GetReportDefinition(PreviewItemContext itemContext)
at Microsoft.Reporting.LocalService.GetCompiledReport(PreviewItemContext itemContext, Boolean rebuild, ControlSnapshot& snapshot)
at Microsoft.Reporting.LocalService.CompileReport()
at Microsoft.Reporting.LocalService.Microsoft.Reporting.ILocalProcessingHost.CompileReport()
at Microsoft.Reporting.WinForms.LocalReport.EnsureExecutionSession()
--- End of inner exception stack trace ---
at Microsoft.Reporting.WinForms.LocalReport.EnsureExecutionSession()
at Microsoft.Reporting.WinForms.LocalReport.SetParameters(IEnumerable`1 parameters)
at Keshav_Spice_Restaurant.Dashboard.dataGridView1_KeyDown(Object sender, KeyEventArgs e)
at System.Windows.Forms.Control.OnKeyDown(KeyEventArgs e)
at System.Windows.Forms.DataGridView.OnKeyDown(KeyEventArgs e)
at System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m)
at System.Windows.Forms.DataGridView.ProcessKeyEventArgs(Message& m)
at System.Windows.Forms.Control.ProcessKeyMessage(Message& m)
at System.Windows.Forms.Control.WmKeyChar(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.DataGridView.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Button event code
  1. if (MessageBox.Show("Print Report!""Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) {  
  2.   LocalReport report = new LocalReport();  
  3.   
  4.   report.ReportPath = Application.StartupPath + "\\Report1.rdlc";  
  5.   OleDbCommand cmd;  
  6.   string stcmd1 = "select * from getinvoice_data where Cus_ID=@d ";  
  7.   cmd = new OleDbCommand(stcmd1, con);  
  8.   cmd.Parameters.AddWithValue("@d", Dashboard.idpass);  
  9.   OleDbDataReader dbr;  
  10.   dbr = cmd.ExecuteReader();  
  11.   while (dbr.Read()) {  
  12.     ReportParameterCollection reportparamters = new ReportParameterCollection();  
  13.     string invoice = Convert.ToString(dbr["Cus_ID"]);  
  14.     reportparamters.Add(new ReportParameter("invoice", invoice));  
  15.     reportparamters.Add(new ReportParameter("table", dbr["Tab_Number"as String));  
  16.     var check = Convert.ToString(dbr["T_Date"]);  
  17.     reportparamters.Add(new ReportParameter("tdate", check));  
  18.     reportparamters.Add(new ReportParameter("totalamount", dbr["Grand_Total"as String));  
  19.     report.SetParameters(reportparamters);  
  20.   }  
  21.   //Bill_Report br = new Bill_Report();    
  22.   //br.Show();    
  23.   //con.Close();    
  24.   DataSet1 ds = GetData();  
  25.   report.DataSources.Add(new ReportDataSource("DataSet1", ds.Tables[0]));  
  26.   PrintToPrinter(report);  
  27. }  
  1. private DataSet1 GetData() {  
  2.   OleDbCommand cmd;  
  3.   string stcmd2 = "select * from getinvoice_data where Cus_ID=@b";  
  4.   cmd = new OleDbCommand(stcmd2, con);  
  5.   cmd.Parameters.AddWithValue("@b", Dashboard.idpass);  
  6.   OleDbDataAdapter da = new OleDbDataAdapter(cmd);  
  7.   DataSet1 ds = new DataSet1();  
  8.   da.Fill(ds, "DataTable1");  
  9.   return ds;  
  10. }  
  1. public static void PrintToPrinter(LocalReport report) {  
  2.   Export(report);  
  3. }  
  4. public static void Export(LocalReport report, bool print = true) {  
  5.   string deviceInfo = @"<DeviceInfo>    
  6.                <OutputFormat>EMF</OutputFormat>    
  7.                <PageWidth>8in</PageWidth>    
  8.                <PageHeight>18in</PageHeight>    
  9.                <MarginTop>0in</MarginTop>    
  10.                <MarginLeft>0in</MarginLeft>    
  11.                <MarginRight>0in</MarginRight>    
  12.                <MarginBottom>0n</MarginBottom>    
  13.            </DeviceInfo>";  
  14.   Warning[] warnings;  
  15.   m_streams = new List < Stream > ();  
  16.   report.Render("Image", deviceInfo, CreateStream, out warnings);  
  17.   foreach(Stream stream in m_streams)  
  18.   stream.Position = 0;  
  19.   
  20.   if (print) {  
  21.     Print();  
  22.   }  
  23. }  
  24. public static void Print() {  
  25.   if (m_streams == null || m_streams.Count == 0) throw new Exception("Error: no stream to print.");  
  26.   PrintDocument printDoc = new PrintDocument();  
  27.   if (!printDoc.PrinterSettings.IsValid) {  
  28.     throw new Exception("Error: cannot find the default printer.");  
  29.   }  
  30.   else {  
  31.     printDoc.PrintPage += new PrintPageEventHandler(PrintPage);  
  32.     m_currentPageIndex = 0;  
  33.     printDoc.Print();  
  34.   }  
  35. }  
  36. public static Stream CreateStream(string name, string fileNameExtension, Encoding encoding, string mimeType, bool willSeek) {  
  37.   Stream stream = new MemoryStream();  
  38.   m_streams.Add(stream);  
  39.   return stream;  
  40. }  
  41. public static void PrintPage(object sender, PrintPageEventArgs ev) {  
  42.   Metafile pageImage = new  
  43.   Metafile(m_streams[m_currentPageIndex]);  
  44.   
  45.   // Adjust rectangular area with printer margins.    
  46.   Rectangle adjustedRect = new Rectangle(  
  47.   ev.PageBounds.Left - (int) ev.PageSettings.HardMarginX, ev.PageBounds.Top - (int) ev.PageSettings.HardMarginY, ev.PageBounds.Width, ev.PageBounds.Height);  
  48.   
  49.   // Draw a white background for the report    
  50.   ev.Graphics.FillRectangle(Brushes.White, adjustedRect);  
  51.   
  52.   // Draw the report content    
  53.   ev.Graphics.DrawImage(pageImage, adjustedRect);  
  54.   
  55.   // Prepare for the next page. Make sure we haven't hit the end.    
  56.   m_currentPageIndex++;  
  57.   ev.HasMorePages = (m_currentPageIndex < m_streams.Count);  
  58. }  
  59. public static void DisposePrint() {  
  60.   if (m_streams != null) {  
  61.     foreach(Stream stream in m_streams)  
  62.     stream.Close();  
  63.     m_streams = null;  
  64.   }  
  65. }  

Brought to you by:

Answers (3)