get application path

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
 
R

Romain TAILLANDIER

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
 
M

Mattias Sjögren

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
 
M

Mattias Sjögren

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top