Skip to main content

ReadFromWebStorage

Description

Retrieves the value stored in the browser web storage for the given key.

Syntax

// Reads a key from application specific storage.
const value = await MFiles.ReadFromWebStorage(keyName);

Parameters

NameTypeDescription
keystringThe web storage key.

Return type

TypeDescription
Promise < string >The value as string stored in web storage for the given key.

Example

This sample demonstrates the use of M-Files API functions to interact with web storage: it writes "Sample Value" to storage with the key "testKey", reads it back, logs the value to the console, and finally deletes the entry from web storage.

note

Values written to web storage must be string values, because they are internally serialized into string values.


// Called when the UI Extension starts
async function OnNewShellUI(shellUI) {

// Write to web storage some value
await MFiles.WriteToWebStorage( "testKey", "Sample Value" );

// Read the value from the web storage
const storedValue = await MFiles.ReadFromWebStorage( "testKey" );

// Outputs: "Sample Value"
console.log( storedValue );

// Remove key from the storage.
await MFiles.DeleteFromWebStorage( "testKey" );

}