Class BaseDirectory
- Namespace
- Xdg.Directories
- Assembly
- Xdg.Directories.dll
The XDG Base Directory specification is a standard created by freedesktop.org that standardizes the location of storing application files.
public static class BaseDirectory
- Inheritance
-
BaseDirectory
- Inherited Members
Remarks
This allows users to have less clutter in their home directories, and allows programmers to not have to hard-code directories.
For all base directories, the directories are resolved as follows:
-
The respective
XDG_*enivronment variable will always be used if specified -
Windows Use Known Folders. macOS Follow the Apple documentation on application-specific files. Linux/FreeBSD Follow the XDG Base Directory specification.
Properties
BinHome
Base directory for executable files.
public static string BinHome { get; }
Property Value
- string
A single base directory relative to which user-specifc executable files should be written.
Remarks
If XDG_BIN_HOME is set, the directory specified.
| Windows |
""
Windows does not support this by default. |
| macOS |
""
macOS does not support this by default. |
| Linux/FreeBSD |
$HOME/.local/bin
|
NOTE: This is not an XDG standard but a de facto standard.
CacheHome
Base directory for non-essential data.
public static string CacheHome { get; }
Property Value
- string
A single base directory relative to which user-specifc non-essential data should be written.
Remarks
If XDG_CACHE_HOME is set, the directory specified.
| Windows |
%LOCALAPPDATA%\cache
|
| macOS |
$HOME/Library/Caches
|
| Linux/FreeBSD |
$HOME/.cache
|
ConfigDirs
A list of directories to look for configuration files.
public static IList<string> ConfigDirs { get; }
Property Value
- IList<string>
A set of preference-ordered base directories to which configuration files should be searched.
Remarks
If XDG_CONFIG_DIRS is set, a list of the directories specified.
| Windows |
%ProgramData%,
%APPADATA%
|
| macOS |
~/Library/Preferences,
/Library/Application Support,
/Library/Preferences
|
| Linux/FreeBSD |
/etc/xdg
|
This is typically not used, for most use cases ConfigHome should be used instead.
ConfigHome
Base directory for configuration files.
public static string ConfigHome { get; }
Property Value
- string
A single base directory relative to which user-specifc configuration files should be written.
Remarks
If XDG_CONFIG_HOME is set, the directory specified.
| Windows |
%LOCALAPPDATA%
|
| macOS |
$HOME/Library/Application Support
|
| Linux/FreeBSD |
$HOME/.config
|
DataDirs
A list of directories to search for data files.
public static IList<string> DataDirs { get; }
Property Value
Remarks
If XDG_DATA_DIRS is set, a list of the directories specified.
| Windows |
%APPADATA%,
%ProgramData%
|
| macOS |
/Library/Application Support
|
| Linux/FreeBSD |
/usr/local/share/,
/usr/share/
|
DataHome
Base directory for data files.
public static string DataHome { get; }
Property Value
- string
A single base directory relative to which user-specifc data files should be written.
Remarks
If XDG_DATA_HOME is set, the directory specified.
| Windows |
%LOCALAPPDATA%
|
| macOS |
$HOME/Library/Application Support
|
| Linux/FreeBSD |
$HOME/.local/share
|
RuntimeDir
Base directory for runtime-specific files.
public static string RuntimeDir { get; }
Property Value
- string
A single base directory relative to which user-specifc runtime files should be written.
Remarks
If XDG_RUNTIME_DIR is set, the directory specified.
| Windows |
%LOCALAPPDATA%
|
| macOS |
$HOME/Library/Application Support
|
| Linux/FreeBSD |
/run/user/$UID
|
StateHome
Base directory for state data.
public static string StateHome { get; }
Property Value
- string
A single base directory relative to which user-specifc state data should be written.
Remarks
If XDG_STATE_HOME is set, the directory specified.
| Windows |
%LOCALAPPDATA%
|
| macOS |
$HOME/Library/Application Support
|
| Linux/FreeBSD |
$HOME/.local/state
|
Methods
BinFile(string)
Location for a binary file, following XDG best practices.
If the directory specified does not exist, it will be created. If the directory cannot be created, the exception will be passed up in a stacktrace perserving way.
public static string BinFile(string relPath)
Parameters
relPathstringThe name of the binary file, and (optionally) the parent directories.
Returns
- string
A suitable location for the specified binary file.
Exceptions
- IOException
The directory specified by
pathis a file.-or-
The network name is not known.
- UnauthorizedAccessException
The caller does not have the required permission.
- ArgumentException
.NET Framework and .NET Core versions older than 2.1:
pathis a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the GetInvalidPathChars() method.-or-
pathis prefixed with, or contains, only a colon character (:).- ArgumentNullException
pathis null.- PathTooLongException
The specified path, file name, or both exceed the system-defined maximum length.
- DirectoryNotFoundException
The specified path is invalid (for example, it is on an unmapped drive).
- NotSupportedException
pathcontains a colon character (:) that is not part of a drive label ("C:").
CacheFile(string)
Location for a cache file, following XDG best practices.
If the directory specified does not exist, it will be created. If the directory cannot be created, the exception will be passed up in a stacktrace perserving way.
public static string CacheFile(string relPath)
Parameters
relPathstringThe name of the cache file, and (optionally) the parent directories.
Returns
- string
A suitable location for the specified cache file.
Exceptions
- IOException
The directory specified by
pathis a file.-or-
The network name is not known.
- UnauthorizedAccessException
The caller does not have the required permission.
- ArgumentException
.NET Framework and .NET Core versions older than 2.1:
pathis a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the GetInvalidPathChars() method.-or-
pathis prefixed with, or contains, only a colon character (:).- ArgumentNullException
pathis null.- PathTooLongException
The specified path, file name, or both exceed the system-defined maximum length.
- DirectoryNotFoundException
The specified path is invalid (for example, it is on an unmapped drive).
- NotSupportedException
pathcontains a colon character (:) that is not part of a drive label ("C:").
ConfigFile(string)
Location for a configuration file, following XDG best practices.
If the directory specified does not exist, it will be created. If the directory cannot be created, the exception will be passed up in a stacktrace perserving way.
public static string ConfigFile(string relPath)
Parameters
relPathstringThe name of the config file, and (optionally) the parent directories.
Returns
- string
A suitable location for the specified config file.
Exceptions
- IOException
The directory specified by
pathis a file.-or-
The network name is not known.
- UnauthorizedAccessException
The caller does not have the required permission.
- ArgumentException
.NET Framework and .NET Core versions older than 2.1:
pathis a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the GetInvalidPathChars() method.-or-
pathis prefixed with, or contains, only a colon character (:).- ArgumentNullException
pathis null.- PathTooLongException
The specified path, file name, or both exceed the system-defined maximum length.
- DirectoryNotFoundException
The specified path is invalid (for example, it is on an unmapped drive).
- NotSupportedException
pathcontains a colon character (:) that is not part of a drive label ("C:").
DataFile(string)
Location for a data file, following XDG best practices.
If the directory specified does not exist, it will be created. If the directory cannot be created, the exception will be passed up in a stacktrace perserving way.
public static string DataFile(string relPath)
Parameters
relPathstringThe name of the data file, and (optionally) the parent directories.
Returns
- string
A suitable location for the specified data file.
Exceptions
- IOException
The directory specified by
pathis a file.-or-
The network name is not known.
- UnauthorizedAccessException
The caller does not have the required permission.
- ArgumentException
.NET Framework and .NET Core versions older than 2.1:
pathis a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the GetInvalidPathChars() method.-or-
pathis prefixed with, or contains, only a colon character (:).- ArgumentNullException
pathis null.- PathTooLongException
The specified path, file name, or both exceed the system-defined maximum length.
- DirectoryNotFoundException
The specified path is invalid (for example, it is on an unmapped drive).
- NotSupportedException
pathcontains a colon character (:) that is not part of a drive label ("C:").
StateFile(string)
Location for a state file, following XDG best practices.
If the directory specified does not exist, it will be created. If the directory cannot be created, the exception will be passed up in a stacktrace perserving way.
public static string StateFile(string relPath)
Parameters
relPathstringThe name of the state file, and (optionally) the parent directories.
Returns
- string
A suitable location for the specified state file.
Exceptions
- IOException
The directory specified by
pathis a file.-or-
The network name is not known.
- UnauthorizedAccessException
The caller does not have the required permission.
- ArgumentException
.NET Framework and .NET Core versions older than 2.1:
pathis a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the GetInvalidPathChars() method.-or-
pathis prefixed with, or contains, only a colon character (:).- ArgumentNullException
pathis null.- PathTooLongException
The specified path, file name, or both exceed the system-defined maximum length.
- DirectoryNotFoundException
The specified path is invalid (for example, it is on an unmapped drive).
- NotSupportedException
pathcontains a colon character (:) that is not part of a drive label ("C:").