Click here to Skip to main content
14,330,208 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hii,
I had created an application in c#.
But when i **move this appication to another drive,folder or PC.
I got error at crystal report **path. and need to change the path at every time when appication moved.
How to fix this problem.
means how to add it into c# resources so that path will be fix.
for eg
cryRpt.Load(????);

thanks in advance.
swapnil
Posted
Updated 1-Sep-19 21:08pm
v2
Rate this:
Please Sign up or sign in to vote.

Solution 2

If it's a web application
report.Load(Server.MapPath("Report1.rpt"));//C#

report.Load(Server.MapPath("Report1.rpt"))'VB.NET

else if it's a windows application
report.Load(Application.StartupPath + "Report1.rpt");//C#

report.Load(Application.StartupPath & "Report1.rpt")'VB.NET

BTW for windows applications you can use other paths like CommonAppDataPath, ExecutablePath, LocalUserAppDataPath, UserAppDataPath. For more info Clickety[^]

FYI check this Tip/Trick
Crystal Reports: Fix for "Load report failed" error.[^]
   
v2
Comments
swapnilKumbhar 18-Jan-12 3:00am
   
thanks for replying guys.
But before deploying an application,if project needed to be moved to another PC.
How to set path.
do i have to hard coded it.

And 1 more
i use .xml file,so at database expert to should i set the path of .xml file after deploying.
Member 12961701 17-Apr-18 3:33am
   
I am using c# WPF but I can't get Application.startupPath
Any Idea how to solve it???
thatraja 17-Apr-18 4:52am
   
I never worked on WPF but these could help you.
https://stackoverflow.com/questions/938421/getting-the-applications-directory-from-a-wpf-application
https://stackoverflow.com/questions/10926506/how-to-get-current-application-path-in-wpf
Rate this:
Please Sign up or sign in to vote.

Solution 4

ReportDocument rptdoc = new ReportDocument();
                rptdoc.Load(Server.MapPath("~\\Reports\\ProjectReport.rpt"));
                rptdoc.SetDataSource(dt);
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 5

keep the crystal report in the same folder in which your code resides and do not specify any path just specify crystal report's file name in code.
Have fun
   
Rate this:
Please Sign up or sign in to vote.

Solution 7

Application.StartupPath does not include \ character at the end. Hence, \ is to be prefixed to the file name
report.Load(Application.StartupPath + "\\Report1.rpt") 
   
Comments
Jeremiah Maramba 6-Oct-14 4:19am
   
this one works for me thanks alot :))
Rate this:
Please Sign up or sign in to vote.

Solution 1

Do you mean dynamic path instead of hard-code path? If yes then store the reports files in application directory & call by the below way.

If it's web application
report.Load(Server.MapPath("Report1.rpt"));


else it's windows application


report.Load(Application.StartupPath + "Report1.rpt");
   
Comments
P.L.Wijayarathna 25-Mar-12 11:12am
   
report.Load(Application.StartupPath + "Report1.rpt") this is not working
P.L.Wijayarathna 25-Mar-12 11:19am
   
report.Load(Application.StartupPath + "Report1.rpt"); not working
Rate this:
Please Sign up or sign in to vote.

Solution 8

In Window application, you don't need to specify Application.StartupPath. You can directly specify relative path of the file but make sure that Properties of file has 'Copy to Output Directory' with value 'Copy always'.
   
Comments
satpal rawat 19-Mar-18 0:48am
   
relative path of the file means we can hard code the palth like this:

ReportDocument cryRpt = new ReportDocument();

cryRpt.Load(@"C:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\Projects\NewProjectdemo\NewProjectdemo\test.rpt");
Rate this:
Please Sign up or sign in to vote.

Solution 9

Try this

report.Load(Application.StartupPath & "/Report1.rpt")


It worked for me


Cheers
   
Comments
CHill60 9-Feb-14 8:57am
   
Reason for my downvote = You have added nothing to the answers that were posted 2 years ago.
Manoj Jagdale 16-Jul-18 6:14am
   
how to set path for crustal report in c# windows application when its shown the error
reports not load
Rate this:
Please Sign up or sign in to vote.

Solution 12

Application does not define startup path
cryRpt.Load(Application.Current + "\\ItemWiseReports.rpt");
   
v2
Comments
CHill60 15-Mar-19 5:10am
   
Reason for my down vote - you have added nothing to the other solutions that were posted 7 years ago. If you are going to revive old posts by adding a solution, make sure you are bringing something new to the thread.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100