I am using the ConfigurationManager in a Class Library and I want to read the config file for the Class Library project. The ConfigurationManager wants to read the config file for the applicaiton. How do I read the Class Library config file?

<html>
Dim strCBFile = ConfigurationManager.AppSettings("CBFile")
</html>

Recommended Answers

All 2 Replies

I hope this will help you:

Dim myMap As New ExeConfigurationFileMap
myMap.ExeConfigFilename = "MyConfigFile.exe.config"
Dim cs As Configuration = ConfigurationManager.OpenMappedMachineConfiguration(myMap)

This worked for me. I still need to know the path for the config, but I can use the .Net config file set up in the IDE for the class library.

The previous post returned the machine config. This is not what was needed.

Dim strConfig As String = "C:\Code\dot NET\CCMC\AppComm\BytePro\ByteProToCBInvoker\bin\Debug\ByteProToCBInvoker.dll"
        Dim config As System.Configuration.Configuration = ConfigurationManager.OpenExeConfiguration(strConfig)
        Dim csSection As AppSettingsSection = config.AppSettings

        Dim strDBPath As String = csSection.Settings("DBPath").Value
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.