GeneXus has specific data types such as Directory and File that allow working directly with the file system. However, in Smart Devices several restrictions exist in relation to which directories can be manipulated by the application, either in Apple or Android smart devices.
The Directory data type has 3 static, read-only properties which help the developer to work with the file system in Smart Devices and Web/Win applications.
The directory where the files related to the application are stored.
In iOS offline applications, this path matches the “Documents” folder path inside the application.
In Android offline applications, this path matches the “Private Storage” folder path of the application.
For the other generators (Web or Win) this path matches the “%USERPROFILE%” directory.
The directory where temporary files of the application are stored.
For offline applications, either iOS or Android, files and folders in this directory may be removed by the operating system. In addition, it is important for the developer to check if these files or directories have been correctly removed.
For the other generators (Web or Win) this path matches the “%TEMP%” directory.
The path to the external storage device, if it exists; otherwise, this property has the value of the property "ApplicationDataPath".
In iOS, because there are no devices with external storage, this property has the same value as the “ApplicationDataPath” property. The same happens to Android devices when they don't have an external storage device.
All these properties do NOT include the file separator character at the end of the path. Therefore, the developer has to include it by using the Separator method of the File data type.
In smart device applications with Online architecture, the Start, Refresh and Load events run on the server-side. Therefore, if these properties are used in these events, their values will use the server property values mentioned above. See Server-side Events in Smart Devices for more information.
If the specified path is relative, the default directory is “Directory.ApplicationDataPath”.
Therefore, this line of code:
&file.Source = "someFile.txt"
… is equal to this line of code:
&file.Source = Directory.ApplicationDataPath + &file.Separator + "someFile.txt"
In Android Smart Devices, absolute paths are supported and they always start with the character “/”. For instance:
&file.Source = "/sdcard/image.jpg"
In iOS Smart Devices, absolute paths are not supported by the platform.
In iOS, access is supported to the directory where the KB images are located by using a variable path called “$RESOURCES”. For example, if the Knowledge Base has an image called “MyImage.png”, you can use this stub of code to use the image:
&file.Source = "$RESOURCES/MyImage.png"
&destPath = Directory.TemporaryFilesPath + &file.Separator + "MyImageCopy.png"
These properties are available as from GeneXus X Evolution 3.