Keiwando.NFSO.NativeFileSO
instance method
OpenFiles
public void OpenFiles (SupportedFileType[] supportedTypes, Action<bool, OpenedFile[]> onCompletion)
Summary
Presents a native dialog to the user which allows them to select multiple
files to be opened at once. The selected file contents are then loaded
into memory managed by instances of the OpenedFile
class.
Parameters
supportedTypes
onCompletion
Examples
The following example demonstrates how to prompt the user to select files to be opened and then handle the results of that operation accordingly.
// Determine which file types the user can choose from.
SupportedFileType[] fileTypes = {
SupportedFileType.PlainText
};
OpenFiles(fileTypes, delegate(bool filesWereOpened, OpenedFile[] files) {
if (filesWereOpened) {
foreach (var file in files) {
// Process the loaded file contents, e.g. using
// OpenedFile.ToUTF8String()
.
}
} else {
// The file selection was cancelled.
}
});
Remarks
The supportedTypes
array is just an indicator to the native file chooser
dialog to only allow the user to choose from files of predefined types.
However, this is not a guarantee that the chosen files are going to contain
data in the correct file format.
For one, the file chooser on Android allows the user to circumvent the file type filter and ultimately select arbitrary files. At the same time, the file choosers that rely on filtering the files based on their extension can be "cheated" by simply changing the file extensions of an arbitrary file.
You should therefore always check whether the opened files inside of the onCompletion
callback contain valid data, instead of assuming that the
file types are always correct.