Skip to main content

IMoBroFileManager

The IMoBroFileManager provides a simple way for plugins to read and write files. All files are stored in the plugin's own data directory and remain available between plugin starts.

caution

The data directory is part of the plugin's installation. All files are deleted when the plugin is updated to a new version, reinstalled or uninstalled.

Storage Location​

EnvironmentDirectory
Installed in MoBroThe files folder inside the plugin's installation directory.
Running locally./data, relative to the working directory. Can be changed using MoBroPluginBuilder.WithStorageDirectory.

File names are resolved relative to this directory. A PluginException is thrown if a file name is invalid or points outside of it (e.g. ..\other.txt).

Example​

public class Plugin : IMoBroPlugin
{
private readonly IMoBroFileManager _files;

public Plugin(IMoBroFileManager files)
{
_files = files;
}

public void Init()
{
if (!_files.Exists("cache.json"))
{
_files.WriteText("cache.json", "{}");
}

var cache = _files.ReadText("cache.json");
}
}

Functions​

Exists(string): bool​

Checks whether the specified file exists.

Parameters​

NameTypeDescription
fileNamestringThe name of the file.

Returns​

true if the file exists; otherwise false.


WriteText(string, string)​

Writes the text content to the specified file. An existing file is overwritten.

Parameters​

NameTypeDescription
fileNamestringThe name of the file.
contentstringThe text content to be written.

WriteBytes(string, byte[])​

Writes the byte array to the specified file. An existing file is overwritten.

Parameters​

NameTypeDescription
fileNamestringThe name of the file.
contentbyte[]The byte array content to be written.

ReadText(string): string​

Reads the text content of the specified file.

Parameters​

NameTypeDescription
fileNamestringThe name of the file.

Returns​

The text content of the file.


ReadBytes(string): byte[]​

Reads the content of the specified file as a byte array.

Parameters​

NameTypeDescription
fileNamestringThe name of the file.

Returns​

The content of the file.