Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 2807

Re: Editing .rpt files in Visual Studio 2015

$
0
0

Hi Patryk,

 

I did release SP 15 yesterday so use it....

 

Easy enough to do, build an array of reports in your folder and then cycle through them open/close/dispose and you can then either export them to RPT format which has saved data or use the SaveAs method and save them into a different folder.

 

First one is to export:

 

if (ExportTypeSelected == "crReportExportFormatCrystalReports")

{

    // this gets the report name and sets the export name to be the same less the extension

    string outputFileName = "";

    string MyRptName = rpt.FileName.ToString();

    outputFileName = MyRptName.Substring(9, rpt.FileName.Length - 9);

    outputFileName = outputFileName.Substring(0, (outputFileName.Length - 4)) + "1.rpt";

 

    try

    {

        if (File.Exists(outputFileName))

        {

            File.Delete(outputFileName);

        }

 

        CrystalDecisions.ReportAppServer.ReportDefModel.RPTExportFormatOptions RasRPTExpOpts = new RPTExportFormatOptions();

 

        try

        {

            RasRPTExpOpts = rptClientDoc.get_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatCrystalReports);

        }

        catch (Exception ex)

        {

            btnSQLStatement.Text = "ERROR: " + ex.Message;

            //return;

        }

 

        CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions exportOpts1 = new CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions();

        exportOpts1.ExportFormatType = CrReportExportFormatEnum.crReportExportFormatCrystalReports;

        exportOpts1.FormatOptions = RasRPTExpOpts;

 

        // And Export

        rptClientDoc.PrintOutputController.ExportEx(exportOpts1).Save(outputFileName, true);

        MessageBox.Show("Export to RPT Completed. NOTE: report is *1.RPT", "", MessageBoxButtons.OK, MessageBoxIcon.Information);

 

    }

    catch (Exception ex)

    {

        btnSQLStatement.Text = "ERROR: " + ex.Message;

        return;

    }

}

 

This one to use SaveAs, I check to see if RAS modified the report and save that object otherwise use the engine to save the report:

 

private void btnSaveReportAs_Click(object sender, System.EventArgs e)

{

    saveFileDialog.Filter = "Crystal Reports (*.rpt)|*.rpt";

    if (DialogResult.OK == saveFileDialog.ShowDialog())

    {

 

        object saveFolder = System.IO.Path.GetDirectoryName(saveFileDialog.FileName);

        string saveFileName = System.IO.Path.GetFileName(saveFileDialog.FileName);

 

        if (!IsRpt)

        {

            try

            {

            rptClientDoc.SaveAs(saveFileName, ref saveFolder,

                (int)CdReportClientDocumentSaveAsOptionsEnum.cdReportClientDocumentSaveAsOverwriteExisting);

            }

            catch (Exception ex)

            {

                btnSQLStatement.Text = "ERROR: " + ex.Message;

                return;

            }

        }

        else

        {

            try

            {

                rpt.SaveAs(saveFolder + "\\" + saveFileName, true);

            }

            catch (Exception ex)

            {

                btnSQLStatement.Text = "ERROR: " + ex.Message;

            }

        }

    }

}

 

You may want to update the DB connection info as well.

Also recommended you get someone to verify these reports to make sure they do work properly.

 

Standalone CR SDK does not have a migration tool to update the reports since its easy enough to write your own...

 

Don


Viewing all articles
Browse latest Browse all 2807

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>