How to get dynamic path for load Report Document?

Nov 24 2011 8:16 AM
Dear honors,
 
I'm developing one windows application. In that project i've some crystal reports. When I click the print button the report should print automatically. The following code works fine in my local system. If I run my in project another system it gets error.. So I need your suggestion, how to get the dynamic path for load Report Document?..
 
Here my code:
 
public void PrintMethod()
{
lsInvNo = frmCustomerInv.gsInvNo;
string query2 = "select InvNo from tblCustomerInvoice where InvNo='" + lsInvNo + "' and State=''";
string InvoNu = DataAccess.GetSingleValue(query2);
if (InvoNu == "")
{
lsInvNo = "";
MessageBox.Show("This Invoice Number Not in Customer Invoice List!", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
Query = "select distinct p.InvNo,p.InvDate ,p.CustomerName,p.TinNo,p.Sno,p.vehicleNo,p.ProductName,p.ProductKg,p.Packing,p.Units,p.Rate,p.Amount,p.Address,a.Mobile,a.CSTNO,c.NetAmt,c.Tax,c.TotAmt,w.Words from tblCustomerInvoice as p inner join tblCustomerDetails as a on p.CustomerName=a.CustomerName inner join tblcustomerInvoiceAmt as c on c.InvNo=p.InvNo inner join tblCustomerInvWords as w on p.InvNo=w.InvNo where p.InvNo='" + lsInvNo + "'order by Sno";
 
}
else
{
SqlCon = dbCon.DBOpenConnection();
Query = "select distinct p.InvNo,p.InvDate ,p.CustomerName,p.TinNo,p.Sno,p.vehicleNo,p.ProductName,p.ProductKg,p.Packing,p.Units,p.Rate,p.Amount,p.Address,a.Mobile,a.CSTNO,c.NetAmt,c.Tax,c.TotAmt,w.Words from tblCustomerInvoice as p inner join tblCustomerDetails as a on p.CustomerName=a.CustomerName inner join tblcustomerInvoiceAmt as c on c.InvNo=p.InvNo inner join tblCustomerInvWords as w on p.InvNo=w.InvNo where p.InvNo='" + lsInvNo + "'order by Sno";
}
SqlDa = new SqlDataAdapter(Query, SqlCon);
DataTable dt = new DataTable();
dt.Clear();
SqlDa.Fill(dt);
ReportDocument REportDoct = new ReportDocument();
REportDoct.Load(@"D:\vsp\vsp\Project\Reports\FinalInvoice.rpt");
REportDoct.SetDataSource(dt);
crystalReportViewer1.ReportSource = REportDoct;
crystalReportViewer1.Refresh();
REportDoct.PrintToPrinter(1, false, 0, 0);

}
 

Thanks in Advance..

Answers (1)