Relative addresses in ImageLocation property

I have difficulty with giving relative addresses in ImageLocation property.

Imagine my webpage store in this address:
~/Webpages/a.aspx

My reports store in this address:
~/App_Data/a.frx

And my image store in this address:
~/Images/a.png

Now what value ImageLocation property must have?
I already tried "../Images/a.png" but it didnt worked and for troubleshooting I need to know if I assign ImageLocation in correct way or not.

Much appreciated

Comments

  • edited 1:23AM
    I am experiencing the same problem with the Winforms version.

    Absolute image locations work fine but relative locations simply won;'t load the image....

    pitty
  • Hello!

    The PictureObject.ImageLocation property allows relative paths not relative to the location of the .frx template or .aspx page, but relative to the process's current working directory (Environment.CurrentDirectory). In web applications running under IIS, the process’s working directory typically points to the server’s system directory, and ASP.NET virtual paths starting with ~/ are not converted by the report engine.

    A reliable method is to pass the full physical path (or full URL) to ImageLocation:

    1. Setting it in code before `Prepare()` (ASP.NET WebForms):

    PictureObject pic = report.FindObject(“Picture1”) as PictureObject;
    if (pic != null)
    {
    pic.ImageLocation = Server.MapPath(“~/Images/a.png”);
    }
    

    (For WinForms, use `Path.Combine(AppDomain.CurrentDomain.BaseDirectory, “Images”, “a.png”);`; for ASP.NET Core, use `IWebHostEnvironment.WebRootPath` or `ContentRootPath`.)

    2. Via a report parameter (convenient for multiple images): In C#, pass the base directory:

    report.SetParameterValue(“ImagesDir”, Server.MapPath(“~/Images”));

    Then, in the BeforePrint event of the Picture1 object in the report script, construct the path:

    private void Picture1_BeforePrint(object sender, EventArgs e)
    {
    Picture1.ImageLocation = System.IO.Path.Combine((string)Report.GetParameterValue(“ImagesDir”), “a.png”);
    }
    
This discussion has been closed.