简体   繁体   中英

Path crystal report c#

I want that my crystal report, if the project is moved to another folder, keeps working without changing the code. Thats the code right now in my WinForm

ReportDocument cryRpt = new ReportDocument();
        string reportPath = Path.Combine(Environment.CurrentDirectory, "CrystalReport1.rpt");
        cryRpt.Load(reportPath);
        crystalReportViewer1.ReportSource = cryRpt;
        crystalReportViewer1.Refresh();

错误

It means : Operation not supported. Can not open a document prepared by the JRC engine stack C + +

Are you sure the rpt file is present?

Looks like error is refering to other problem, not the file location.

Try this, in order to test if file location is the problem or not:

ReportDocument cryRpt = new ReportDocument();

        string rpt = "CrystalReport1.rpt";
        string reportFolder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

        string reportPath = Path.Combine(reportFolder, rpt);

        if(!File.Exists(reportPath))
        {
             MessageBox.Show("File " + rpt + " not found in " + reportFolder );
             return;
        }
        cryRpt.Load(reportPath);
        crystalReportViewer1.ReportSource = cryRpt;
        crystalReportViewer1.Refresh();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM