get application path

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
how can I get the path of my application? If the application is located in
C:\Program Files\MyApp, I want to be able to get this path in the code so I
can save a text file in this location.

Thanks
Julia
 
System.Windows.Forms.Application.StartupPath

To save any file in the current directory, you just have to precise no file
path.
the file path are relatives by default.

ROM
 
how can I get the path of my application?

In a Winforms application you can check Application.StartupPath. You
can also look at Assembly.Location of the application's startup
assembly and parse out the directory with Path.GetDirectoryName.

If the application is located in
C:\Program Files\MyApp, I want to be able to get this path in the code so I
can save a text file in this location.

I wouldn't recommend doing that, since users often don't have write
access to the application directory. Consider using for example a
subdirectory of
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
instead.



Mattias
 
To save any file in the current directory, you just have to precise no file
path.
the file path are relatives by default.

But they are relative to the current directory
(Environment.CurrentDirectory), which isn't always the same as the
application directory.



Mattias
 
Back
Top