How to get report path.

PatelNehal4u

Active member
Joined
Apr 6, 2009
Messages
25
Programming Experience
1-3
Hello Everyone,

I had created an application named "WindowsApplication1" and created forms in it "Form1" & "Form2", now from just call the form2 and form2 contain a crystalreportviewer1 tool. Now my application also contain a crystalreport which i want to load in crystalreportviewer1 from form1. so i write code like this in form1

VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim crprpt As New ReportDocument

        Dim frm As New Form2

        crprpt.Load(Application.StartupPath & "\CrystalReport1.rpt")

        frm.CrystalReportViewer1.ReportSource = crprpt
        frm.CrystalReportViewer1.Refresh()
        frm.Show()
    End Sub

now Application.StartupPath returning the path which is :

C:\Users\Guest\VisualStudio2008\Projects\WindowsApplication\bin\Debug

and my report is stored in
C:\Users\Guest\VisualStudio2008\Projects\WindowsApplication\


is there any help that i can get my application path, not the execution path.

i also tried something like :

VB.NET:
My.Application.Info.DirectoryPath()
AppDomain.CurrentDomain.BaseDirectory.ToString()
Environment.CurrentDirectory.ToString()
but not satisfied....
 
When running from the design environment, the exe is being created in the bin\debug folder; so that is actually the application path...

You can change your path but the coding would again need to be changed when you released the program. Its better if you either moved the reports into your debug folder during testing or better yet stored the path to the report using application.settings or to a file that you can read dynamically. This way you can change the path later.
 
Thanks for answering, but if i store the path of report folder in Application.settings like ;

ReportPath = "C:\MyApplication\Reports"

So when i deploy the application on client machine and if i put the reports in

D:\MyApplication\Reports

so how can i dynamically change the Application Setting on client machine.
 
My thought with the application file is you can use one path while your debugging and then change the value before compiling for distribution. You could still use application path without the need of hardcoding a value. Personally I dont like application path (causes problems when its on a shared drive with files; not that it would in this case with reports). Other options include putting the reports right into your project so that its embeded in the compiled exe. This has the disadvantage of needing to recompiled whenever you make a report change though. My personal suggestion would be to take a look at using: GetFolderPath(SpecialFolder.LocalApplicationData) you can look at both in the help file to get a better understanding.
 
Back
Top