我应该在哪里存储我的申请数据?

时间:2023-01-13 23:34:32

I have an application that needs to store data. Currently, I am using the built-in Application Settings to do it, but it only gives me two choices: application and user scopes. Ideally, I want a "local" scope that allows the application to run under another user and still find its data rather than recreate it for that user. The application scope can do this, but it's read only. The application data will be changed by the user. It's OK if only the administrator is allowed to make changes to the data.

我有一个需要存储数据的应用程序。目前,我使用内置的应用程序设置来完成它,但它只给我两个选择:应用程序和用户范围。理想情况下,我想要一个“本地”范围,允许应用程序在另一个用户下运行,仍然可以找到它的数据,而不是为该用户重新创建它。应用程序范围可以执行此操作,但它是只读的。应用程序数据将由用户更改。如果只允许管理员对数据进行更改,则可以。

As you probably can guess, I have an administration tool that allows the user to change the data and windows service runner that reads the data and does something with it. It would be great if the windows service runner access the data created by the administration tool.

正如您可能猜到的那样,我有一个管理工具,允许用户更改数据和Windows服务运行器,它可以读取数据并对其执行某些操作。如果Windows服务运行器访问管理工具创建的数据,那将是很好的。

2 个解决方案

#1


7  

If the data is very, very simple, and you need it to be readable by other applications or users (with appropriate permissions), I would probably choose to store it in an XML file or even a plain-text file inside the user's Application Data folder, which would be obtained via Environment.GetFolderPath. An example for saving might look like:

如果数据非常非常简单,并且您需要其他应用程序或用户可以读取(具有适当的权限),我可能会选择将其存储在XML文件中,甚至存储在用户应用程序数据中的纯文本文件中文件夹,将通过Environment.GetFolderPath获取。保存的示例可能如下所示:

using System.IO;
using System.Xml.Linq;

string settingsDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
if (!Directory.Exists(settingsDirectory))
    Directory.CreateDirectory(settingsDirectory);
string fileName = "tasks.xml";
string settingsPath = Path.Combine(settingsDirectory, fileName);
XDocument settingsDoc = new XDocument(
    new XElement("Tasks",
        new XElement("Task",
            new XElement("Name", "Make Breakfast"),
            new XElement("Location", @"C:\Program Files\MyApp\Plugins"),
            new XElement("FileName", "breakfast.dll"))));
// ... etc.
settingsDoc.Save(settingsPath);

That's it - settings saved! You can load them again with XDocument.Load.

就是这样 - 设置已保存!您可以使用XDocument.Load再次加载它们。

#2


0  

Sounds like you want to store it in a database, the question is local or on a network or not. The answer also depends on what kind of data you are storing, how your app is distributed, and other factors.

听起来你想将它存储在数据库中,问题是本地的还是网络上的问题。答案还取决于您存储的数据类型,应用程序的分发方式以及其他因素。

Oh, and BTW we could help you way better if you specify your platform (preferably with a tag)--silverlight, wpf, winforms, asp.net, console, etc.

哦,顺便说一句,如果你指定你的平台(最好带有标签),我们可以帮助你更好 - silverlight,wpf,winforms,asp.net,console等。

#1


7  

If the data is very, very simple, and you need it to be readable by other applications or users (with appropriate permissions), I would probably choose to store it in an XML file or even a plain-text file inside the user's Application Data folder, which would be obtained via Environment.GetFolderPath. An example for saving might look like:

如果数据非常非常简单,并且您需要其他应用程序或用户可以读取(具有适当的权限),我可能会选择将其存储在XML文件中,甚至存储在用户应用程序数据中的纯文本文件中文件夹,将通过Environment.GetFolderPath获取。保存的示例可能如下所示:

using System.IO;
using System.Xml.Linq;

string settingsDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
if (!Directory.Exists(settingsDirectory))
    Directory.CreateDirectory(settingsDirectory);
string fileName = "tasks.xml";
string settingsPath = Path.Combine(settingsDirectory, fileName);
XDocument settingsDoc = new XDocument(
    new XElement("Tasks",
        new XElement("Task",
            new XElement("Name", "Make Breakfast"),
            new XElement("Location", @"C:\Program Files\MyApp\Plugins"),
            new XElement("FileName", "breakfast.dll"))));
// ... etc.
settingsDoc.Save(settingsPath);

That's it - settings saved! You can load them again with XDocument.Load.

就是这样 - 设置已保存!您可以使用XDocument.Load再次加载它们。

#2


0  

Sounds like you want to store it in a database, the question is local or on a network or not. The answer also depends on what kind of data you are storing, how your app is distributed, and other factors.

听起来你想将它存储在数据库中,问题是本地的还是网络上的问题。答案还取决于您存储的数据类型,应用程序的分发方式以及其他因素。

Oh, and BTW we could help you way better if you specify your platform (preferably with a tag)--silverlight, wpf, winforms, asp.net, console, etc.

哦,顺便说一句,如果你指定你的平台(最好带有标签),我们可以帮助你更好 - silverlight,wpf,winforms,asp.net,console等。