Click here to Skip to main content
15,902,635 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello everyone ,, this is my first question here be good question,,,,
i have c# application that contain crystal reports , everything work fine except when i change file location and it will give error "loading field"
C#
ReportDocument rpt = new ReportDocument();
            rpt.Load("C:\\Users\\mypce\\Desktop\\file \\CrystalReport1.rpt");
            crystalReportViewer1.ReportSource = rpt;

so what i want is make path dynamically , or can i put this path in config file that i can change any time ,,,
Posted

You can simply define path of report in config file as discussed here:
http://stackoverflow.com/questions/13152765/declare-a-string-in-web-config-file[^]
As described at below link, use following code:
XML
<appsettings>
    <add key="dir" value="YourReportPathHereInProperFormat" />
  </appsettings>

C#
string dir = ConfigurationManager.AppSettings["dir"].ToString();

For more look into "AppSettings" at below article:
Web.config File - ASP.NET[^]
Thanks.
 
Share this answer
 
v3
thanks for your replay, i do work in application is this for web?
however i know this is right answer but i didn't use it correctly
i used it like this
C#
//ReportDocument rpt = new ReportDocument();
           string crystalrp = ConfigurationManager.AppSettings["cry"].ToString();
           crystalReportViewer1.ReportSource = crystalrp; 

and didn't work sorry but can you help me with this plz,,,
 
Share this answer
 
v2
C#
string st = ConfigurationManager.AppSettings["crystalrp"].ToString();
         ReportDocument rpt = new ReportDocument();
         rpt.Load(st);
            crystalReportViewer1.ReportSource = rpt ;

thank you so much for helps ,,,,
 
Share this answer
 

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