如何阅读应用程序设置 [英] How to read application settings

查看:113
本文介绍了如何阅读应用程序设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在写一个两个项目的应用程序。让我们调用第一个项目ProjectA和第二个项目ProjectB。



ProjectA包含所有应用程序设置,是一个WinForms应用程序。 ProjectB是一个需要读取ProjectA设置的服务。所以这是我遵循的步骤。



1.使ProjectA的设置属性访问修饰符公开而不是内部

2.添加引用到ProjectB中的ProjectA

3.添加一个用于在ProjectB中定义ProjectA的命名空间

4.这样的代码:

bLvl6Rpt = ProjectA.Properties .Settings.Default.Lvl6Report;



我在bLvl6Rpt中得到的是Lvl6Report的默认值,而不是实际设置的值。如何从ProjectA读取实际设置?我知道我可以用XML文件轻松完成这项工作,但是我正在努力学习它是如何工作的。



谢谢,

Glenn

Hi,

I'm writing a two project application. Lets call the first project, ProjectA and the second project ProjectB.

ProjectA contains all the application settings and is a WinForms application. ProjectB is a Service that needs to read ProjectA's settings. So here's the steps I've followed.

1. Make ProjectA's Settings Property Access Modifier Public instead of Internal
2. Add a reference to ProjectA in ProjectB
3. Add a Using to define ProjectA's Namespace in ProjectB
4. Code like this:
bLvl6Rpt = ProjectA.Properties.Settings.Default.Lvl6Report;

What I get in bLvl6Rpt is Lvl6Report's default value, not what is actually set. How do I read the actual settings from ProjectA? I know I can do this easy with an XML file, however I'm trying to learn how this works.

Thank you,
Glenn

推荐答案

尝试

用.NET 2.0读/写App.Config文件 [ ^ ]

如何:从Web.config文件中读取应用程序设置 [ ^ ]


概念错误。

如果这是一个单个用户的应用程序,它看起来像共享设置。因此,请将设置文件存储在公共位置(例如%PROGRAMDATA%\YourCompany \YourProductSuite \SharedSettings.xml)。用于管理设置的类进入一个dll,桌面应用程序和服务都使用这个类。

如果服务处理多个客户端应用程序并且应该应用客户端特定的设置,例如设置实际上是服务方法的参数,应该作为方法参数从客户端传递给服务。
The concept is wrong.
If this is an application for a single user, it looks like shared settings. Consequently, store the settings file in a common location (e.g. %PROGRAMDATA%\YourCompany\YourProductSuite\SharedSettings.xml). The classes used for managing the settings go into one dll which is used by both your desktop application and the service.
If the service deals with several client applications and is expected to apply client-specific settings, such settings are actually parameters to methods of the service and ought to be passed to the service as method parameters from the client.


我认为你可以使用网络服务轻松实现这一点。

请参阅此链接。它可能会对您有所帮助。

C#和.Net中的Web服务 [ ^ ]
I think you can achieve this easily using web-services.
Refer this link.It may help you.
Web Services in C# and .Net[^]


这篇关于如何阅读应用程序设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆