Winforms report viewer resets Directory.CurrentDirectory

1 Answer 17 Views
Report Viewer - WinForms
Richard
Top achievements
Rank 1
Iron
Iron
Iron
Richard asked on 12 Jan 2026, 11:19 AM

I have an old VB.NET(.NET8) winforms app which loads some resources on sign in using 

Image.FromFile("resources\\myImage.png"

This is loaded from the resources sub folder in the runtime directory - so far so good. I also allow the user to change the "focus" of the application, which loads a different image, again so far so good - all of the images are correctly found.

However, if I show the Winforms report viewer, the Directory.CurrentDirectory is reset from the correct runtime folder to the folder which contained the report (which is a UNC share)

This means that loading the images fails - it's looking in the reports directory rather than the runtime directory.

Any one have any ideas on how to solve this?

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 15 Jan 2026, 08:55 AM

Hi Richard,

Thank you for the provided information about the problem!

I couldn't reproduce the described behavior locally with the latest version of the product - Telerik Reporting - ProgressĀ® TelerikĀ® Reporting 2025 Q4 (19.3.25.1119). I will also share the code that I tested with for reference:

Imports System
Imports System.Diagnostics
Imports System.IO
Imports System.Windows.Forms

Public Partial Class MainForm
    Inherits Form

    Public Sub New()
        Trace.WriteLine("1-------------------" & Directory.GetCurrentDirectory())
        Me.InitializeComponent()
        AddHandler Me.Load, AddressOf Me.Form1_Load
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs)
        Me.reportViewer.RefreshReport()
        Trace.WriteLine("2-------------------" & Directory.GetCurrentDirectory())
    End Sub
End Class

In my test, I tried writing the current directory to the trace before and after the WinForms Report Viewer was initialized, but the directory remained the same in both cases(bin/debug/net8.0-windows).

With that being said, if you are indeed experiencing different behavior, I will share some suggestions on how to resolve the issue below.

Recommended Solutions:

Set the Base Directory for Images used inside Reports

I am not sure whether you are using the method Image.FromFile externally or inside the report, but if it is the latter, and you use the method to provide an image to a PictureBox report item, you can specify a base directory for such resources in the App.config file of the project. For example:

<Telerik.Reporting>
    <processing>
        <!--The element below represents a Path resource resolver:-->
        <resourceResolver provider="path">
            <parameters>
                <parameter name="directory" value="c:\\CommonResourcesDirectory\\" />
            </parameters>
        </resourceResolver>
    </processing>
</Telerik.Reporting>

For more information on setting a base directory for the resources used in the reports, you can take a look at the Configuring the processing Element - Telerik Reporting article.

Use Absolute Paths for Resource Loading:

Instead of relying on relative paths, always build the absolute path to your resources based on your application's startup directory. For example:

Dim resourcePath As String = Path.Combine(Application.StartupPath, "resources\myImage.png")
Dim img As Image = Image.FromFile(resourcePath)

This way, image loading is not affected by changes to the current directory..

Store and Restore the Current Directory:

Before showing the ReportViewer, store the current directory. After closing or initializing the ReportViewer, restore it:

Dim originalDir As String = Directory.GetCurrentDirectory()
' Show the ReportViewer
Directory.SetCurrentDirectory(originalDir)

This ensures your application continues to resolve relative paths as expected.

Set the Current Directory Explicitly:

After initializing or closing the ReportViewer, explicitly set the current directory back to your desired folder:

Directory.SetCurrentDirectory(Application.StartupPath)

Additional Notes:

  • This path change can also affect subreports and external resources like stylesheets if they use relative paths.
  • If you have reports with subreports or external resources, consider passing the full path as a parameter to the report, or programmatically updating the report sources before displaying them.

I hope that the provided information and suggestions are helpful. In case you need further assistance, please send me a runnable project where the issue is reproducible, so that I can debug it locally.

    Regards,
    Dimitar
    Progress Telerik

    Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

    Tags
    Report Viewer - WinForms
    Asked by
    Richard
    Top achievements
    Rank 1
    Iron
    Iron
    Iron
    Answers by
    Dimitar
    Telerik team
    Share this question
    or