How to open web.config file from custom action installer class, located in DLL.

One of the readers of the my post “Using VS 2005 Web Setup Project with custom actions” asked how to pick web.config file. that is actually part of the web project, from custom action installer class located in a separate DLL.

 With an assumption that DLL with installer class located in the BIN folder of the web project , you can do the following:

Dim asm As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
Dim sConfigFileName As String FSHelperLib.AppSettingsHelper.GetConfigFileName(asm)


        public static string GetConfigFileName(Assembly ExecutingAssembly)


            string sPath = “”;

            { //root folder one level up from bin

                sPath = SystemHelper.GetWebRootFolder(ExecutingAssembly);

                sPath = sPath + @”web.config”;


            if (!File.Exists(sPath))


                throw new FileNotFoundException(“Missing config file “ + sPath);


            return sPath;


 See also My SystemHelper class for GetWebRootFolder definition.