Tuesday, August 5, 2008

ReportViewer changes application path once report exported (WinForm)

Apparently a bug, when a report is exported on a winform using the ReportViewer control, it changes the path for the application. If application tries to access any local files then it will look in the directory where the report was exported.

Solution is to save the path before the reportviewer is displayed and change it back to application path when the form is closed. The following two events worked in my case.

Dim _AppDirectory As String

Private Sub ReportViewerForm_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed

Environment.CurrentDirectory() = Me._AppDirectory


End Sub


Private Sub ReportViewerForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Me._AppDirectory = Environment.CurrentDirectory()


End Sub



Link:
http://forums.msdn.microsoft.com/en-US/vsreportcontrols/thread/d5d5e224-f906-4c3f-88e0-258ee2b2e149/

No comments: