how to get application path

  • Thread starter Thread starter ALI-R
  • Start date Start date
A

ALI-R

Hi
The default direcoty when debugging the appication is always
"...\myC#proramme\bin\Debug" and cuases problem because my xml files are in
"...\myC#proramme" .

Is there a way of getting the root direcoty of my
application("...\myC#proramme") in my code?

thanks for your time.
 
Why not store your xml files in the Application's folder, the User's profile
folder, or the Common app data folder? These are the folder's most
applications use to store their files and there are methods of the
Application class that obtain them for you.

I recommend you take a look at these and see if they will be of help:
Application.UserAppDataPath
Application.CommonAppDataPath
Application.ExecutablePath

ShaneB
 
Hi...

From my point of view, there's something wrong here...

First, your "...\myC#proramme\" directory exists only when you're developing
your application, so when you distribute it, the end user chooses the final
directory, for example, "C:\Program Files\MyAppDirectory".

Having said that, and if your program is a Windows Forms application, you
can find your application path with Application.StartupPath, and it will
work in developing and run time.
In developing time, Application.StartupPath will return
"...\myC#proramme\bin\Debug" and in run time it will return the directory
choosen by the end user.

If you want to access a file in run time, but you don't want it to be
located in your final application directory, you can add it to your project
and compile it as a embedded resource, then you can access it with the
ResourceManager class (you can read about it in the MSDN documentation).

Feel free to send me messages for dicussing any topic you want...

Good luck...

Bye...
 
Back
Top