有没有办法告诉 .NET 在哪里查找用户设置文件?

发布于 2024-08-26 00:11:58 字数 152 浏览 3 评论 0原文

基本上我们的应用程序的多个实例将被启动,但它们需要有单独的用户设置。我们目前为此使用“用户设置”,并且它对于单个实例(每个 Windows 用户)运行良好,但我们希望能够使用通过命令行传入的设置路径来启动多个实例。有没有办法使用内置的 .NET 设置来做到这一点,还是我们必须自己进行设置?

Basically multiple instances of our application will be launched but they need to have separate user settings. We currently have use "user settings" for that, and it works fine for a single instance (per windows user) but we would like to be able to launch multiple instances with say a settings path passed in via command line. Is there a way to do this with the built-in .NET settings or will we have to roll our own?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

森罗 2024-09-02 00:11:58

LocalFileSettingsProvider 类是使用用户设置管理文件的类,因此几乎不可能进行调整。不管是谁写的,一定是因为安全问题而陷入瘫痪。也许并非没有道理。

如果您想坚持使用 System.Configuration 那么您需要实现自己的提供程序。最好的方法可能是从 RegistrySettingsProvider 示例 开始。它不会帮助您正确处理文件,但至少您将有一些可以构建的东西。使用 Reflector 查看几次会有所帮助。

The LocalFileSettingsProvider class, the one that manages the file with user settings, is quite impossible to tweak. Whomever wrote that must have been paralyzed by security concerns. Perhaps not unjustified.

If you want to stick with System.Configuration then you'll need to implement your own provider. Probably the best way to do that is to start from the RegistrySettingsProvider sample. It won't help you get the file handling right but at least you'll have something to build on. A couple of peeks with Reflector can help.

蓝梦月影 2024-09-02 00:11:58

我建议开发一个类来处理应用程序设置并接受文件名。我必须对需要应用程序设置的 DLL 执行此操作,如果您想将设置存储在非本地位置(例如网络上的单个位置),它也会有所帮助。

它将给您带来更大的灵活性 - 这绝对值得投资!

I recommend developing a class that will handle app settings and accepts a filename. I've had to do this for DLLs that needed app settings, and it also helps if you want to store your settings in a non-local location (e.g. single place on the network).

It will give you a lot more flexibility - It's definitely worth the investment!

无所的.畏惧 2024-09-02 00:11:58

.Net 有一个配置提供程序 API。 app.config 只是该 API 的预定义实现。您应该考虑使用 API 来扩展内置 API,或者创建您自己的 API。

.Net has a Configuration Provider API. app.config is just a predefined implementation of that API. You should look into using the API to either extend the built-in API, or create your own.

硪扪都還晓 2024-09-02 00:11:58

我建议将配置信息存储在数据库中并根据用户读取。任何情况下你都必须维护用户特定信息的不同副本。应用程序的加载从数据库读取并缓存所有设置。

用户 用户个性化和配置文件 API 用于检索信息。更新数据库中的信息非常容易,而不是处理位于用户系统中的文件。

I would suggest to store the config information in DB and read based on the user. Any case you have to maintain the user specific information different copies. Onload of the application read from DB and cache all the settings.

User User Personalization and profile API to retrieve the information. It is very easy to update the information in DB rather then dealing with files which are located in users systems.

神魇的王 2024-09-02 00:11:58

有一篇有趣的 CodeProject 文章自定义设置提供商。您只需要对代码进行一些小调整,然后它就可以将您的设置保存并加载到您提供的文件位置。

There is an interesting CodeProject article which has a custom settings provider. You only need a small tweak of your code, and then it allows you to save and load your settings to a file location you provide.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文