1
votes

I'm using Crystal Reports to generate report definition *.rpt files. I later create reports using those definition files from inside my application.

I have a special image called the logo that sits in my application's file directory. I'd like to reference this logo on my crystal report. The logo is always located a couple directories up from my report, but the root directory and the host computer can change between installations, so the file structure could look like this:

image: c:\files\logo.png
report: c:\files\reports\type1\myreport.rpt

or like this:

image: \\filehost\files\logo.png
report: \\filehost\\files\reports\type1\myreport.rpt

Does Crystal have a way to reference this image in a formula with a relative path? Does the .rpt file contain a reference to it's file location that I could build off of to grab this image?

Edit: @campagnolo_1 mentions that Crystal has a "File Path and Name" special field, but I don't see a way to use that in the image file location script.

Edit 2: @campagnolo_1 has provided a solution in the comments on his answer. Thanks campagnolo_1!

2

2 Answers

3
votes

Crystal has a special field for the file path and name. You could use that to find out where the report file is located and extract the path if needed. Then you can use that to dynamically reference your image file. Here is a post with some step-by-step instructions.

1
votes

I always stream my logos in as part of the underlying data that the report is bound against. I add the column to the dataset by doing something like this:

DataTable dt = GetYourDataTable();
dt.Columns.Add(new DataColumn("imagepath", typeof(string)));
dt.Columns.Add(new DataColumn("image", typeof(System.Byte[])));             
ds.Tables.Add(dt);

And populate it with:

using (FileStream fs = new FileStream(szFilePath, FileMode.Open))
{
    using (BinaryReader br = new BinaryReader(fs))
    {
          foreach (DataRow dr in _dtReportData.Rows)
          {
               dr["imagepath"] = szFilePath;
               dr["image"] = br.ReadBytes((int)br.BaseStream.Length);
          }
    }
}

I know it's redundant to set EVERY ROW, but it does work, and the object can just be added to the report as a Blob.

The big advantage for you would be that the image location is arbitrary.. you only need to know it at data-retrieval time, not at report-rendering time.