Skip to end of metadata
Go to start of metadata

Most of the time user need to store data for your application, even if only to save information about the application state, so the session and contextual information is not lost. With LocalStorageService, you can read, write, and delete files to the local device storage.

The LocalFolderKind enumeration is available to determine the folder path for each platform, so you won't need to bother with different API or settings in different platforms. The types of local folder kind that supported in Intersoft Crosslight are Data, Documents, Downloads, Cache, Temporary, and Custom.

On this page:

Checking File Availability

Before you do any work with a file in the local storage, you should check whether the file is available. The following code shows how to determine whether the specified file name existed in the local folder.

Save a File on Local Storage

If you would like to write a file into local storage at your device, you can always use the following method. A file named fileName is created if it is not yet existed. You can also specify the FileWriteMode enumeration to determine the file write strategy if the file already existed, you can either append or overwrite the file.

Save a Text Files on Local Storage

The following code shows how to create and write to a text file. A text file named textFileName.txt is created if don’t already exist. You can also specify the FileWriteMode enumeration to determine the file write strategy if the file already existed, you can either append or overwrite the file.

Read a File on Local Storage

If you would like to read a file from your local storage, you can simply use this method and specify the file name you want to read, and where to look for that file.

Read a Text Files on Local Storage

The following code shows how to read the text data. You just need to specify the name of text file and where the text file is placed.

Get the Full Path of a Folder

To get full path name of a folder, you can use this method, just set it with the specified folder kind.

Get the Full Path of a File

To get full path name of file, you can use the following method, supplied with the specified file name and the folder kind.

Delete a File

You can always delete files that you no longer need. The easiest way to delete a file is to call the following method.