Kavitha
Kavitha

Reputation: 113

How can i get the path of my application?

I want the path of my application for loading crystal report,

Dim Report As New ReportDocument  
Report.Load("D:\xxx\xx\x\ Report.rpt")  

instead of hard coding the path i need it using code because i don't know where my customer will install this application.

so i tried following code

filepath = Path.GetDirectoryName(Application.ExecutablePath) 

but it is returning path as D:\xxx\xx\x\bin\
I dont want that Bin in my path because my report is available in "D:\xxx\xx\x\ Report.rpt" so what can i do here?

Upvotes: 1

Views: 5422

Answers (2)

Steve
Steve

Reputation: 216353

Yor are doing the right thing. Do not change that code.

When your application runs inside the IDE (DEBUG or RELEASE) the Executable path is defined by the properties of your project in the Output Dir property of your project(BUILD tab).
When your application is deployed then the path is exactly what you expect to be.

To resolve your situation you should set the property Copy To Output Directory on each of your report files. In this way the IDE will copy the report wherever you define the Output Directory in the project property

Another option (the more flexible one, but more code is needed) is to define, in your config file, a custom setting that contains the location of your reports. You will be able to update this setting with the path of your reports with a manual or automatic update during deployment (or after it the need arises to move somewhere else the reports).
Of course, when you load the reports you should look at this property and build the path accordingly

Upvotes: 4

tinstaafl
tinstaafl

Reputation: 6958

try

filepath = Path.GetDirectoryName(Application.ExecutablePath + "\..")

that will return the folder just before bin.

Upvotes: 0

Related Questions