Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where should I store my application data?

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.

like image 952
ATL_DEV Avatar asked May 04 '10 18:05

ATL_DEV


People also ask

Where should I store application data in Linux?

If an app is running as an ACTUAL user, the data should be stored under that users $HOME. If it is a system user, the install (as root or similar) should give that user ownership of its files and directories under /var, and add the user to any groups needed for access to additional devices/directories/files.

Where do programs store files?

By default, the Program Files folder is found on the root directory of the primary hard drive, with the C:\Program Files path. To open this folder on your computer, follow the steps below. Open File Explorer. Select This PC or Computer.

Where do Windows programs store data?

On modern versions of Windows, you'll see a “ProgramData” folder on your system drive—usually the C:\ drive. This folder is hidden, so you'll only see it if you show hidden files in File Explorer.

How do I find the application data folder in Google Drive?

Application data folder scope Before you can access the application data folder, you must request access to the https://www.googleapis.com/auth/drive.appdata scope. For more information about scopes and how to request access to them, refer to Authenticate your users.


1 Answers

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:

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.

like image 159
Aaronaught Avatar answered Oct 17 '22 02:10

Aaronaught