Click here to Skip to main content
15,867,999 members
Please Sign up or sign in to vote.
5.00/5 (1 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

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

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

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

VB
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.[^]
 
Share this answer
 
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
C#
ReportDocument rptdoc = new ReportDocument();
                rptdoc.Load(Server.MapPath("~\\Reports\\ProjectReport.rpt"));
                rptdoc.SetDataSource(dt);
 
Share this answer
 
v2
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
 
Share this answer
 
Application.StartupPath does not include \ character at the end. Hence, \ is to be prefixed to the file name
C#
report.Load(Application.StartupPath + "\\Report1.rpt") 
 
Share this answer
 
Comments
Jeremiah Maramba 6-Oct-14 4:19am    
this one works for me thanks alot :))
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
C#
report.Load(Server.MapPath("Report1.rpt"));


else it's windows application


C#
report.Load(Application.StartupPath + "Report1.rpt");
 
Share this answer
 
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
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'.
 
Share this answer
 
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");
Try this

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


It worked for me


Cheers
 
Share this answer
 
Comments
CHill60 9-Feb-14 8:57am    
Reason for my downvote = You have added nothing to the answers that were posted 2 years ago.
[no name] 16-Jul-18 6:14am    
how to set path for crustal report in c# windows application when its shown the error
reports not load
Application does not define startup path
cryRpt.Load(Application.Current + "\\ItemWiseReports.rpt");
 
Share this answer
 
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900