Skip to content

File reader

Alexanderius edited this page Jul 3, 2025 · 3 revisions

File reader

FileReader is the class for loading localizable text files from the data folder specified in Simplify.Web configuration.

  • File names should contain a language prefix. For example, if you are loading the file Menu.xml, it should be named Menu.{language}.xml in the data folder.
  • The file will be loaded for the current language. If the current language file does not exist, then the file for the default language will be loaded.

Example

public class MyController : Controller
{
    public override ControllerResponse Invoke()
    {
        // Loads Menu.en.xml file
        var myData = FileReader.LoadXDocument("Menu.xml");
        ...
    }
}

If you are loading XML files via LoadXDocument, you can specify the file name without extension

public class MyController : Controller
{
    public override ControllerResponse Invoke()
    {
        // Loads Menu.en.xml file
        var myData = FileReader.LoadXDocument("Menu");
        ...
    }
}

You can also load text files (for example, HTML files)

public class MyController : Controller
{
    public override ControllerResponse Invoke()
    {
        // Loads SomeFile.html
        var myData = FileReader.LoadTextDocument("SomeFile.html");
        ...
    }
}

Files can be cached in memory by specifying the second parameter

...
FileReader.LoadTextDocument("SomeFile.html", true);
FileReader.LoadXDocument("Menu", true);
...

File cache can be globally disabled via Simplify.Web configuration.

<< Previous page Next page >>

Clone this wiki locally