Get path of configuration file for current running application using C#

In programming world everything is not a piece of cake. At times you need to do things more than available out-of-the-box. One of the common thing you seems to do is to modify or access your application’s configuration.

There are two type of configuration files:

  1. App.Config (Used by Windows Project type application)

  2. Web.Config (Used by Web Project type application)

We do lots of dirty stuffs to get the path and name of the file that is main configuration for the windows or web application.

The simplest way to access the configuration file associated with the currently running application is using:


Verified against: Windows Forms, Console Application, WPF Application, ASP.NET MVC 3 application.