TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Hardik Prajapati
NA
15
3.5k
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
if
(MessageBox.Show(
"Print Report!"
,
"Message"
, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) {
LocalReport report =
new
LocalReport();
report.ReportPath = Application.StartupPath +
"\\Report1.rdlc"
;
OleDbCommand cmd;
string
stcmd1 =
"select * from getinvoice_data where Cus_ID=@d "
;
cmd =
new
OleDbCommand(stcmd1, con);
cmd.Parameters.AddWithValue(
"@d"
, Dashboard.idpass);
OleDbDataReader dbr;
dbr = cmd.ExecuteReader();
while
(dbr.Read()) {
ReportParameterCollection reportparamters =
new
ReportParameterCollection();
string
invoice = Convert.ToString(dbr[
"Cus_ID"
]);
reportparamters.Add(
new
ReportParameter(
"invoice"
, invoice));
reportparamters.Add(
new
ReportParameter(
"table"
, dbr[
"Tab_Number"
]
as
String));
var check = Convert.ToString(dbr[
"T_Date"
]);
reportparamters.Add(
new
ReportParameter(
"tdate"
, check));
reportparamters.Add(
new
ReportParameter(
"totalamount"
, dbr[
"Grand_Total"
]
as
String));
report.SetParameters(reportparamters);
}
//Bill_Report br = new Bill_Report();
//br.Show();
//con.Close();
DataSet1 ds = GetData();
report.DataSources.Add(
new
ReportDataSource(
"DataSet1"
, ds.Tables[0]));
PrintToPrinter(report);
}
private
DataSet1 GetData() {
OleDbCommand cmd;
string
stcmd2 =
"select * from getinvoice_data where Cus_ID=@b"
;
cmd =
new
OleDbCommand(stcmd2, con);
cmd.Parameters.AddWithValue(
"@b"
, Dashboard.idpass);
OleDbDataAdapter da =
new
OleDbDataAdapter(cmd);
DataSet1 ds =
new
DataSet1();
da.Fill(ds,
"DataTable1"
);
return
ds;
}
public
static
void
PrintToPrinter(LocalReport report) {
Export(report);
}
public
static
void
Export(LocalReport report,
bool
print =
true
) {
string
deviceInfo = @"<DeviceInfo>
<OutputFormat>EMF</OutputFormat>
<PageWidth>8in</PageWidth>
<PageHeight>18in</PageHeight>
<MarginTop>0in</MarginTop>
<MarginLeft>0in</MarginLeft>
<MarginRight>0in</MarginRight>
<MarginBottom>0n</MarginBottom>
</DeviceInfo>";
Warning[] warnings;
m_streams =
new
List < Stream > ();
report.Render(
"Image"
, deviceInfo, CreateStream,
out
warnings);
foreach
(Stream stream
in
m_streams)
stream.Position = 0;
if
(print) {
Print();
}
}
public
static
void
Print() {
if
(m_streams ==
null
|| m_streams.Count == 0)
throw
new
Exception(
"Error: no stream to print."
);
PrintDocument printDoc =
new
PrintDocument();
if
(!printDoc.PrinterSettings.IsValid) {
throw
new
Exception(
"Error: cannot find the default printer."
);
}
else
{
printDoc.PrintPage +=
new
PrintPageEventHandler(PrintPage);
m_currentPageIndex = 0;
printDoc.Print();
}
}
public
static
Stream CreateStream(
string
name,
string
fileNameExtension, Encoding encoding,
string
mimeType,
bool
willSeek) {
Stream stream =
new
MemoryStream();
m_streams.Add(stream);
return
stream;
}
public
static
void
PrintPage(
object
sender, PrintPageEventArgs ev) {
Metafile pageImage =
new
Metafile(m_streams[m_currentPageIndex]);
// Adjust rectangular area with printer margins.
Rectangle adjustedRect =
new
Rectangle(
ev.PageBounds.Left - (
int
) ev.PageSettings.HardMarginX, ev.PageBounds.Top - (
int
) ev.PageSettings.HardMarginY, ev.PageBounds.Width, ev.PageBounds.Height);
// Draw a white background for the report
ev.Graphics.FillRectangle(Brushes.White, adjustedRect);
// Draw the report content
ev.Graphics.DrawImage(pageImage, adjustedRect);
// Prepare for the next page. Make sure we haven't hit the end.
m_currentPageIndex++;
ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
}
public
static
void
DisposePrint() {
if
(m_streams !=
null
) {
foreach
(Stream stream
in
m_streams)
stream.Close();
m_streams =
null
;
}
}
Reply
Answers (
3
)
How do I change the line space in the wrapped label text
WinForm Elementhost with WPF doesn´t show 3d Graphic