Q:

Get Application File Path in Windows Forms Application

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?

A:

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

