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)

where  

        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.

 

posted @ Monday, August 14, 2006 9:13 AM

Print

Comments on this entry:

No comments posted yet.

Your comment:



 (will not be displayed)


 
 
 
Please add 2 and 8 and type the answer here:
 

Live Comment Preview:

 
«August»
SunMonTueWedThuFriSat
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456