How to get.exe Current Directory During Installation and Read Config File in C#

May 29, 2024
Reaction score
We have developed a Windows application that sends files to an SFTP server. Each installation requires a unique configuration (such as the SFTP path), so we plan to store this information in a config.ini file. When the installer is triggered, it needs to read the config.ini file and save the information to the Windows registry.

Our goal is to ensure that the .exe file and the config.ini file are in the same directory. When the .exe file is executed, the application needs to determine its current directory in order to access the config.ini file. How can we achieve this in a C# application?


^ The World's First ^
May 10, 2010
Reaction score
This forum does not really help with application coding but a simple google search returned:
should give you the path of the executing program in C#.

If you need additional assistance with C# I would encourage you to seek a forum dedicated to coding.

BTW: if the config.ini is to be updated frequently when the exe is run then config.ini really should not be stored in the same folder path as the exe. Windows protects the Program Files directory from writes by requiring UAC administrator privileges which may cause issues if the exe attempts to update config.ini there. If config.ini is only written on install and is read only after that then being in Program Files folder is fine.
Last edited:

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