0

I have a simple windows form app that I need to get the file path for. I am placing a config file in the same directory and I need to be able to get the path to that file.

I have used Application.CommonAppDataPath but that returns the path with 1.0.0.0 at the end.

and Applicaiton.StartupPath but that returns the path with \bin\debug at the end

Is there anyway to get the path to just the main file directory without anything appended to the end?

Mike
  • 12,359
  • 17
  • 65
  • 86

3 Answers3

1

Application.StartupPath is returning the path with \bin\debug on the end because that is where your code is running, at least on your development machine.

If you are going to deploy this away from your development machine then Application.StartupPath will give you what you're asking for - the file path for your application. And yes, if you have deployed the config file to that same location, your code is going to find it.

How to get the application also working on your development machine and get round the bin\debug issue? Well, a dirty hack would be just to chop the bin\debug string off the end of Application.StartupPath.

In that case, if you need to check for whether you're running inside the debugger, see this question

Community
  • 1
  • 1
hawbsl
  • 15,313
  • 25
  • 73
  • 114
0

Try with

Dim aPath As String 
Dim aName As String 

aName = _
  System.Reflection.Assembly.GetExecutingAssembly. _
  GetModules()(0).FullyQualifiedName    

aPath = System.IO.Path.GetDirectoryName(aName) 
pyCoder
  • 503
  • 3
  • 9
  • This gives GetExecutingAssembly() is a method which is not valid in the given context – Mike Nov 03 '10 at 14:21
0

You can use

Application.ExecutablePath; which gives full path including executable file name and

Application.StartupPath; for your current running application path directory without file name

Javed Akram
  • 15,024
  • 26
  • 81
  • 118