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.

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
posted @ Monday, August 14, 2006 9:13 AM
Print

Comments on this entry:

No comments posted yet.

Your comment:



(not displayed)


 
 
 
 
 

Live Comment Preview:

 
«February»
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910