Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
542 views
in Technique[技术] by (71.8m points)

.net - Share Config file for Web and Window App (Best Way)

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:est.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;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

That's an interesting issue. One option is to use a different persistence mechanism that's intended for multiple consumers, like a database. Can you store your config data there?

OR... you could use the answer provided here:

Accessing App.config in a location different from the binary


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...