I have created a Class Library (Core Processing Component) using C# in Visual Studio 2008 and added the reference in Website. Website accessing the class library successfully. Web.config having some configuration values, which is used by the Class Library.
Now, I want to access the same component and configuration in a Window Application (C# VS-2k8). I am able to access the same class library in window application.
But, How do i Share the Web.config file of website with the Window Application? So that, i don’t have to replicate the same configuration.
Thanks.
Update# 1
Further detail on Question 1: I would like to add config file in Class Library instead of having dependent on application’s config file. E.g. web.config in website or app.config in windows application.
This is to reduce the duplicacy/conflicts of same configurations in multiple apps.
Update# 2
I am using the following code to get the configuration from the external location from window and web application. But it is not working for me.
D:\test.exe.config file
<configuration>
<appSettings>
<add key="KeyName" value="KeyValue"/>
</appSettings>
</configuration>
Code Behind:
Configuration config = ConfigurationManager.OpenExeConfiguration("D:\\test.exe.config");
string strValue = config.AppSettings.Settings["KeyName"].Value;
Yes, I got the solution.
Thanks to
Bob HornandJoeBillyfor valuable inputs.I have implemented the configuration as per my requirement. I have searched a lot for the complete solution but always getting the concepts and small piece of code, that’s why i am providing the complete working code.
With the help of below mentioned code you can achieve the followings and play with the configuration as you want.
[CommonDB]can be defined as a singlerepository and can be stored in external XML file. Class library will be getting always one value for web as well as windows application.
[WebDBConn]can be stored in web.config.[WindowDBConn]can be mentioned in app.config.[INPUT_PATH]as per the application, then use same key and the diff values in wen.config and app.config. But remember that key should not be available in the common.config other wise the value which is available in the common.config will be picked up.Common.Configfor Class Library/Common configurationWeb.Configfor WebsiteApp.configfor Windows ApplicationCode behind
Thanks…