Where should I store application data?

I have an application that should store data. I currently use the built-in application settings, but this gives me only two options: the application and user areas. Ideally, I want a β€œlocal” area that allows the application to run as another user and still find its data, rather than recreate it for that user. The application area can do this, but read-only. User data will be changed by the user. This is normal if 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 data and a Windows service runner that reads the data and does something with it. It would be great if the Windows service runner accessed the data created by the administration tool.

+7
settings wpf application-settings settings.settings
source share
2 answers

If the data is very, very simple, and you need it to be readable by other applications or users (with the appropriate permissions), I would probably want to save it in an XML file or even in a text file inside the user’s application data folder, which will be obtained through Environment.GetFolderPath . An example save might look like this:

 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); 

What is it - the settings are saved! You can load them again using XDocument.Load .

+7
source share

It looks like you want to save it to the database, the question is local or online or not. The answer also depends on what data you store, how your application is distributed, and other factors.

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

0
source share

All Articles