views:

116

answers:

2

I have a directory named reports inside my winform project in .net. My project name is AccountingReports and inside that Directory reports exists. So i need the way to access this path via code. In Asp.net we use Request.PhysicalApplicationPath property. So is there any method or property exists that will give me the root of my project

+2  A: 

You can use:

Directory.GetCurrentDirectory

Gets the current working directory of the application.

You can then append "Reports" to that using

Path.Combine(string, string):

Dim reportsFolder As String
reportsFolder = Path.Combine(Directly.GetCurrentDirectory(), "Reports")
ChrisF
Amit Ranjan
@Amit - yes, unless you put the location into the app.config directory and read it from there.
ChrisF
Then in this case after deployment user need to update the app.config file each and every time he moves Reports directory.
Amit Ranjan
@Amit - unless you provide a settings dialog option for them to update it.
ChrisF
+1  A: 

When running in the IDE vs. Installed I have used:

If System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed - true if installed, false IDE

installed - System.Deployment.Application.ApplicationDeployment.CurrentDeployment.DataDirectory

IDE - My.Application.Info.DirectoryPath

dbasnett
still the same My.Application.Info.DirectoryPath = \bin\debug
Amit Ranjan
anyways i need to do some parsing over the string or copy paste it to executable dir..anyways thanks for kind support..
Amit Ranjan