HowTo: Store Files

From $1
Table of contents

To store data in your application, we recommend that you read the file system layout guidelines from Apple that describes the various paths that your application should use.

The <Application_Home>/Documents can be retrieved by calling:

var documents = Environment.GetFolderPath (Environment.SpecialFolder.Personal);

To get the base <Application_Home> directory use:

var basedir = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.Personal), "..");

Other directories relative to basedir include:

basedir/AppName.app Where the executables live.  This is also the current working directory (Environment.CurrentDirectory).
basedir/Documents

Where application-specific data files are stored.   

This directory is backed up by iTunes.

basedir/Library/Preferences

Application-specific configuration settings.   You should manage your settings using the NSUserDefaults class.

This directory is backed up by iTunes.

basedir/Library/Caches

Use this directory to store any cache data to be used across invocations of the application.

Your application is responsible for removing data files from this directory when it no longer needs them.    

basedir/tmp Use for temporary files.

Then you can use any of the System.IO routines to create files or databases in your file system:

using (var o = File.OpenText(Path.Combine(documents, "foo.txt")))
    o.WriteLine("Hello, world!");

 

Tag page

Files (0)

 
Page last modified 19:01, 30 Sep 2009 by jonp