Skip to main content

WriteToWebStorage

Description​

Writes the value in the browser web storage.

Syntax​

// Writes a value for key "keyName" from application specific storage.
await MFiles.WriteToWebStorage( keyName, value );

Parameters​

NameOptionalityTypeDescription
keyRequiredstringThe web storage key.
valueRequiredstringThe value.

Return type​

TypeDescription
Promise < boolean >True / false based on the status.

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" );

}

Exceptions​

ArgumentError - When key or value is null or undefined, or when value is not a string.