Assets

File System

Standard .NET file access is restricted to prevent rogue access to your files, this means you can not use System.IO.File or variants directly.

Instead, s&box provides a BaseFileSystem for several virtual filesystems that can only access files within specific game directories.

There are a few different File Systems available to use in your game. Each one writes and reads from a different location.

Data File System

FileSystem.Data is used to read and write data to a sub-directory specifically for the game that is currently running, i.e. C:\steam\steamapps\common\sbox\data\org\game\

Mounted File System

FileSystem.Mounted is an aggregate filesystem of all mounted content from the core game, the current game and its dependencies.

Organization File System

FileSystem.OrganizationData is a place to store user data across several games in your organization, i.e.

C:\steam\steamapps\common\sbox\data\org\

// If the file doesn't exist already then write some data to it
if ( !FileSystem.Data.FileExists( "player.txt" ) )
    FileSystem.Data.WriteAllText( "player.txt", "Hello, world!" );

// Read the text back into a variable from the file
var hello = FileSystem.Data.ReadAllText( "player.txt" );

:::info WriteJson and ReadJson will only work with Properties of your class unless directed not to - make sure the things you want to save are Properties!

:::

public class PlayerData
{
  	public int Level { get; set; } // Will be serialized
	public int MaxHealth { get; set; } // Will be serialized
	public string Username; // Won't be serialized

	public static void Save( PlayerData data )
	{
		FileSystem.Data.WriteJson( "player.json", data );
	}

	public static PlayerData Load()
	{
		return FileSystem.Data.ReadJson<PlayerData>( "player.json" );
	}
}

Source: Facepunch/sbox-docs (CC-BY-4.0) · updated 2026-08-20. Read it rendered on the official docs.

More in Assets

Community wiki — not affiliated with Facepunch Studios. For the latest and most authoritative information, see the official developer wiki.