0

I created Stock Management System using c# and SQL Server Management Studio. In my system have crystal reports. when I run my project on client machine. its work as expected. but I cannot open crystal report. The reason is given path is not same with the client machine path.

reportDocument.Load(@"E:\Projects\WCC-StockManagementSystem\WCC-StockManagementSystem\Reports\InvoiceReport.rpt");

I want to run my crystal reports without giving full path. I want to change above line like this.

 reportDocument.Load(@"WCC-StockManagementSystem\WCC-StockManagementSystem\Reports\InvoiceReport.rpt");

But if I do it like this. Its not working. Can you please tell me how to solve this problem. this is my full code for loading crystal report.

reportDocument.Load(@"E:\Projects\WCC-StockManagementSystem\WCC-StockManagementSystem\Reports\InvoiceReport.rpt");
        using (SqlConnection con = new SqlConnection(CS))
        {
            DataSet ds = new DataSet();
            SqlDataAdapter sda = new SqlDataAdapter("select MAX(InvoiceNo) InvoiceNo, MAX(Cashier) Cashier, ItemName, Sum(Quantity) Quantity, ItemCode, MAX(DiscountPrice) DiscountPrice, MAX(Amount) Amount, MAX(GrossAmount) GrossAmount, MAX(Cash) Cash, MAX(Balance) Balance, MAX(NoOfItems) NoOfItems from tblTemporaryInvoice group by ItemCode, ItemName ", con);
            DataTable dt = new DataTable();
            sda.Fill(dt);
            reportDocument.SetDataSource(dt);
            crvInvoiceReportViewer.ReportSource = reportDocument;
        }

Please change this code and send me right way to run crystal report on client machine. Thank you

  • This question has not much to do with crystal reports but a lot with how you distributed your application and where the report files files are located. For example, check [this answer](https://stackoverflow.com/questions/15653921/get-current-folder-path) – Cleptus Jan 26 '21 at 09:41
  • Every application must be configure with the information needed for it to execute successfully. You should configure it with the appropriate directory where you intend to store your reports, just like you do with the connection information for your database. – SMor Jan 26 '21 at 12:13

2 Answers2

0

If you don't want to add the path to the Reports folder in the configuration file, then you can put the Reports folder in the same path where the .exe is.

Then you can build the path to find the report using the Environment.CurrentDirectory

reportDocument.Load($"{Environment.CurrentDirectory}\Reports\InvoiceReport.rpt");
EmiFala
  • 51
  • 1
  • 6
  • I cannot type \Reports\InvoiceReport.rtp. its shows red line under the \ mark. – sandanuwan dharmarathna Jan 28 '21 at 14:00
  • You should "escape" with another \. Like reportDocument.Load($"{Environment.CurrentDirectory}\\Reports\\InvoiceReport.rpt"); – EmiFala Jan 28 '21 at 17:01
  • Also you can use: $"{Application.StartupPath}\\Reports\\InvoiceReport.rpt" – EmiFala Jan 28 '21 at 17:02
  • its also not working. When I install my project on client machine and try to open my crystal report. its shows this error. Load report failed. I used this line. its work in my pc. but not client machine. reportDocument.Load(Application.StartupPath.Replace("bin\\Debug", "") + "\\Reports\\InvoiceReport.rpt"); – sandanuwan dharmarathna Jan 29 '21 at 12:14
  • You shouldn't be using Replace("bin\\Debug", ""). If you have the Reports folder in the same folder that the .exe is, both in your PC and in the cliente PC, you don't need to make the Replace. – EmiFala Jan 29 '21 at 12:48
  • EmiFala so can you tell me how can I solve this problem. I used this code its working very well. reportDocument.Load(Environment.CurrentDirectory + "\\Reports\\InvoiceReport.rpt"); But after create my setup exe and install it to my pc. when i try to open crystal report. its says Load report failed. – sandanuwan dharmarathna Jan 29 '21 at 13:03
  • Did you check that you have the folder "Reports" with the InvoiceReport.rpt file in the same folder where you installed the application in the client machine? – EmiFala Jan 29 '21 at 13:41
  • @EmiFale. What is that mean? I did not understand it well – sandanuwan dharmarathna Jan 29 '21 at 15:03
  • In my setup folder I have folder name Application File. Inside of the file I have this file WCC-StockManagementSystem_1_0_0_2, Inside of this file I have Reports file and inside the reports file i have file name InvoiceReport.rpt.deploy. – sandanuwan dharmarathna Jan 29 '21 at 15:06
  • so you have: ..\Application File\WCC-StockManagementSystem_1_0_0_2.exe ..\Application File\Reports\InvoiceReport.rpt It should work. You can debug printing Environment.CurrentDirectory + "\\Reports\\InvoiceReport.rpt" to screen before reportDocument.Load(Environment.CurrentDirectory + "\\Reports\\InvoiceReport.rpt"); to see if you are looking for InvoiceReport.rpt in the right path. – EmiFala Jan 29 '21 at 16:13
  • EmiFala. can you please send me your email address. I will send my project to you. then you can check and please help me to solve – sandanuwan dharmarathna Jan 29 '21 at 16:21
  • EmiFala after I created my setup I run it my pc. Everything working well. also crystal report load. But I install in on another pc its show Load report failed. But problem is why it not run on client machine. No have any idea right now. – sandanuwan dharmarathna Jan 29 '21 at 16:24
  • Did you deploy the Crystal Report runtimes in the Client machine? – EmiFala Jan 29 '21 at 17:43
  • in my pc Sap crystal report runtime engine is 64 bit 13.0.29.3671. In my another pc Sap crystal report runtime engine 64 bit 13.0.12.1494 . I try to find 13.0.29.3671 version. but i did not find it. I found but we need to install visual studio also install 13.0.29.3671 version. – sandanuwan dharmarathna Jan 29 '21 at 17:58
  • You need to update the Sap Crystal runtime in your another PC. You don't need to install Visual Studio. You have to download "SAP Crystal Reports for Visual Studio (SP29) runtime engine for .NET framework MSI (64-bit)" from the oficial SAP webpage. This is the link: https://www.sap.com/cmp/td/sap-crystal-reports-visual-studio-trial.html . – EmiFala Jan 29 '21 at 18:17
  • Thank you so much for your guide and help. After Install it everything working very well. Thank you again and again . Sri – sandanuwan dharmarathna Jan 29 '21 at 19:32
  • Good to know !. Please, don't forget to vote the aswer as useful if it was. – EmiFala Jan 29 '21 at 20:13
  • I created my project using .net framework 4.7.2. When I install my project into client machine we know we need to install .net framework 4.7.2 on client machine. can you send me that like to download .net framework 4.7.2. Reason is my another computer already installed .net framework. there for I no have any idea how to install .net framework into client machine. can you please send me that link also – sandanuwan dharmarathna Jan 30 '21 at 12:22
  • https://dotnet.microsoft.com/download/dotnet-framework/net472 – EmiFala Jan 30 '21 at 13:54
  • EmiFala. In my PC I try to open InvoiceReport.rpt. I want to change some design. But last days its worked very well. But now that design not open. When I try to open it visual studio not working. After that when I click somewhere on visual studio show message. (Visual Studio 2019 is not responding. If you restart or close program. ) Like this. can you please tell me how can I reopen my crystal design file – sandanuwan dharmarathna Feb 02 '21 at 16:20
  • Try reinstalling Crystal Report for Visual Studio. Same link used to download the runtime, but in this case, you need to download SAP Crystal Report for Visual Studio. – EmiFala Feb 02 '21 at 22:04
  • EmiFala I simply restart my PC. now its working well. Thanks for your help – sandanuwan dharmarathna Feb 03 '21 at 08:02
  • I will Install my windows application for client machine. He has two PC. If he say he want to install this windows application for both PC how can I install it. Its mean I want to install server only one pc and another pc also can using this windows application without server. its mean 2 PC and I will install server only one pc. How can I connect both pc – sandanuwan dharmarathna Feb 03 '21 at 08:05
  • When I print my invoice I want to print my footer at the bottom of the page. But after I selected Section Expert ==> Print at bottom of page my footer is not display after I print it. I convert it to pdf for checking footer is showing or not. but it not showing. – sandanuwan dharmarathna Feb 06 '21 at 08:09
0

You no need to provide full path. just create a instance of crystal report.

InvoiceReport rpt = new InvoiceReport();
crvInvoiceReportViewer.ReportSource = rpt;

it will work.