file

(plugins.file)

Overview

The file management plugin offers a comprehensive toolkit for managing files and folders both locally and remotely. It supports operations such as creating, reading, modifying, and deleting files while accommodating various formats, including text, binary, and XML. Advanced features like encoding, content streaming, and size management are also integrated to enhance file interactions on both the client and server sides.

Users can perform essential tasks such as appendToTXTFile, writeFile, and writeXMLFile, which allow appending, creating, or modifying files efficiently. The plugin also supports creating temporary files through createTempFile and managing folder contents with getFolderContents. Folder operations include recursive copying using copyFolder and deletion with deleteFolder, all while providing detailed file attributes such as modification dates via getModificationDate and sizes with getFileSize. Flexible filtering options enable targeted retrieval of folder contents, enhancing workflow precision.

For interactive use, the plugin facilitates file selection dialogs through showFileOpenDialog, supporting multiselect and file type filters, with customizable callback functionality. Large files can be streamed directly to the browser using streamFile without consuming excessive memory, ensuring optimal performance for downloads or inline viewing. Temporary file handling via trackFileForDeletion automates cleanup processes upon solution closure, contributing to resource efficiency.

Properties

Property
Description

servoy.FileServerService.defaultFolder

Set the default folder path (absolute path on the server) to save files sent by clients (will default to user.home/.servoy/uploads/UUID/)

Returned Types

JSFile,

Methods Summarized

Type
Name
Summary

Appends a string given in parameter to a file, using default platform encoding.

Appends a string given in parameter to a file, using the specified encoding.

Appends a string given in parameter to a file, using default platform encoding.

Appends a string given in parameter to a file, using the specified encoding.

Returns a JSFile instance corresponding to an alternative representation of a file (for example a string).

Convenience return to get a JSFile representation of a server file based on its path.

Copies the source file to the destination file.

Copies the sourcefolder to the destination folder, recursively.

Creates a JSFile instance.

Creates the folder by the given pathname, including any necessary but nonexistent parent folders.

Creates a temporary file on disk.

Removes a file from disk.

Deletes a folder from disk recursively.

Returns the default upload location path of the server.

Returns an Array of JSFile instances correponding to the file system root folders.

Returns the size of the specified file.

Returns an array of JSFile instances corresponding to content of the specified folder.

Returns an array of JSFile instances corresponding to content of the specified folder.

Returns an array of JSFile instances corresponding to content of the specified folder.

Returns an array of JSFile instances corresponding to content of the specified folder.

Returns an array of JSFile instances corresponding to content of the specified folder.

Returns an array of JSFile instances corresponding to content of the specified folder.

Returns an array of JSFile instances corresponding to content of the specified folder.

Returns an array of JSFile instances corresponding to content of the specified folder.

Returns an array of JSFile instances corresponding to content of the specified folder.

Returns an array of JSFile instances corresponding to content of the specified folder.

Returns a JSFile instance corresponding to the home folder of the logged in used.

Returns the maximum allowed file size for uploads in KB.

Returns the modification date of a file.

Returns an array of JSFile instances corresponding to content of the specified folder on the server side.

Returns an array of JSFile instances corresponding to content of the specified folder on the server side.

Returns an array of JSFile instances corresponding to content of the specified folder on the server side.

Returns an array of JSFile instances corresponding to content of the specified folder on the server side.

Returns an array of JSFile instances corresponding to content of the specified folder on the server side.

Returns an array of JSFile instances corresponding to content of the specified folder on the server side.

Returns an array of JSFile instances corresponding to content of the specified folder on the server side.

Returns an array of JSFile instances corresponding to content of the specified folder on the server side.

Returns an array of JSFile instances corresponding to content of the specified folder on the server side.

Returns an array of JSFile instances corresponding to content of the specified folder on the server side.

Moves the file from the source to the destination place.

Opens the given local file.

Opens the given data as a file.

Reads all or part of the content from a binary file.

Reads all or part of the content from a binary file.

Reads all or part of the content from a binary file.

Reads all or part of the content from a binary file.

Reads all or part of the content from a binary file.

Read all content from a text file.

Read all content from a text file.

Read all content from a text file.

Read all content from a text file.

Read all content from a text file.

void

Sets the maximum allowed file size for uploads in KB.

void

Stream the given file(path) to the browser with content-disposition:attachment This will not load in the file fully into memory but only stream it right from disk.

void

String the given file(path) to the browser you can provide the content disposition how this should be send (inline or as an attachment) This will not load in the file fully into memory but only stream it right from disk.

void

String the given file(path) to the browser you can provide the content disposition how this should be send (inline or as an attachment) This will not load in the file fully into memory but only stream it right from disk.

void

If the client's solution is closed, the file given to this method will be deleted.

Writes the given file to disk.

Writes the given file to disk.

Writes the given file to disk.

Writes the given file to disk.

Writes data into a text file.

Writes data into a text file.

Writes data into an XML file.

Writes data into an XML file.

Methods Detailed

appendToTXTFile(file, text)

Appends a string given in parameter to a file, using default platform encoding.

Parameters

  • JSFile file a local JSFile

  • String text the text to append to the file

Returns: Boolean true if appending worked

Sample

appendToTXTFile(file, text, encoding)

Appends a string given in parameter to a file, using the specified encoding.

Parameters

  • JSFile file a local JSFile

  • String text the text to append to the file

  • String encoding the encoding to use

Returns: Boolean true if appending worked

Sample

appendToTXTFile(file, text)

Appends a string given in parameter to a file, using default platform encoding.

Parameters

  • String file the file path as a String

  • String text the text to append to the file

Returns: Boolean true if appending worked

Sample

appendToTXTFile(file, text, encoding)

Appends a string given in parameter to a file, using the specified encoding.

Parameters

  • String file the file path as a String

  • String text the text to append to the file

  • String encoding the encoding to use

Returns: Boolean true if the text is successfully appended to the file located at the specified file path using the given encoding; false otherwise.

Sample

convertToJSFile(file)

Returns a JSFile instance corresponding to an alternative representation of a file (for example a string).

Parameters

Returns: JSFile a JSFile instance corresponding to the given file representation, or null if conversion is not possible.

Sample

convertToRemoteJSFile(path)

Convenience return to get a JSFile representation of a server file based on its path.

Parameters

  • String path the path representing a file on the server (should start with "/")

Returns: JSFile the JSFile

Sample

copyFile(source, destination)

Copies the source file to the destination file. Returns true if the copy succeeds, false if any error occurs.

Parameters

Returns: Boolean true if the file was copied successfully; false otherwise.

Sample

copyFolder(source, destination)

Copies the sourcefolder to the destination folder, recursively. Returns true if the copy succeeds, false if any error occurs.

Parameters

Returns: Boolean true if the folder was copied successfully; false otherwise.

Sample

createFile(targetFile)

Creates a JSFile instance. Does not create the file on disk.

Parameters

Returns: JSFile a JSFile instance representing the specified target file.

Sample

createFolder(destination)

Creates the folder by the given pathname, including any necessary but nonexistent parent folders. Note that if this operation fails it may have succeeded in creating some of the necessary parent folders. Will return true if it could make this folder or if the folder did already exist.

Parameters

Returns: Boolean true if the folder was created successfully or already exists; false otherwise.

Sample

createTempFile(prefix, suffix)

Creates a temporary file on disk. A prefix and an extension are specified and they will be part of the file name.

Parameters

Returns: JSFile a JSFile instance representing the created temporary file.

Sample

deleteFile(destination)

Removes a file from disk. Returns true on success, false otherwise.

Parameters

Returns: Boolean true if the file was successfully deleted; false otherwise.

Sample

deleteFolder(destination, showWarning)

Deletes a folder from disk recursively. Returns true on success, false otherwise. If the second parameter is set to true, then a warning will be issued to the user before actually removing the folder.

Parameters

Returns: Boolean true if the file was successfully deleted; false otherwise.

Sample

getDefaultUploadLocation()

Returns the default upload location path of the server.

Returns: String the location as canonical path

Sample

getDiskList()

Returns an Array of JSFile instances correponding to the file system root folders.

Returns: Array an array of JSFile instances representing the root folders of the file system.

Sample

getFileSize(fileOrPath)

Returns the size of the specified file.

Parameters

  • Object fileOrPath can be a (remote) JSFile or a local file path

Returns: Number the size of the specified file in bytes, or -1 if the file is invalid.

Sample

getFolderContents(targetFolder)

Returns an array of JSFile instances corresponding to content of the specified folder. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.

Parameters

  • JSFile targetFolder JSFile object.

Returns: Array an array of JSFile instances representing the contents of the specified folder that match the given filters.

Sample

getFolderContents(targetFolder, fileFilter)

Returns an array of JSFile instances corresponding to content of the specified folder. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.

Parameters

  • JSFile targetFolder JSFile object.

  • Object fileFilter Filter or array of filters for files in folder.

Returns: Array an array of JSFile instances representing the contents of the specified folder that match the given filters.

Sample

getFolderContents(targetFolder, fileFilter, fileOption)

Returns an array of JSFile instances corresponding to content of the specified folder. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.

Parameters

  • JSFile targetFolder JSFile object.

  • Object fileFilter Filter or array of filters for files in folder.

  • Number fileOption 1=files, 2=dirs

Returns: Array an array of JSFile instances representing the contents of the specified folder that match the given filters.

Sample

getFolderContents(targetFolder, fileFilter, fileOption, visibleOption)

Returns an array of JSFile instances corresponding to content of the specified folder. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.

Parameters

  • JSFile targetFolder JSFile object.

  • Object fileFilter Filter or array of filters for files in folder.

  • Number fileOption 1=files, 2=dirs

  • Number visibleOption 1=visible, 2=nonvisible

Returns: Array an array of JSFile instances representing the contents of the specified folder that match the given filters.

Sample

getFolderContents(targetFolder, fileFilter, fileOption, visibleOption, lockedOption)

Returns an array of JSFile instances corresponding to content of the specified folder. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.

Parameters

  • JSFile targetFolder JSFile object.

  • Object fileFilter Filter or array of filters for files in folder.

  • Number fileOption 1=files, 2=dirs

  • Number visibleOption 1=visible, 2=nonvisible

  • Number lockedOption 1=locked, 2=nonlocked

Returns: Array an array of JSFile instances representing the contents of the specified folder that match the given filters.

Sample

getFolderContents(targetFolder)

Returns an array of JSFile instances corresponding to content of the specified folder. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.

Parameters

  • String targetFolder File path.

Returns: Array an array of JSFile instances representing the contents of the specified folder that match the given filters.

Sample

getFolderContents(targetFolder, fileFilter)

Returns an array of JSFile instances corresponding to content of the specified folder. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.

Parameters

  • String targetFolder File path.

  • Object fileFilter Filter or array of filters for files in folder.

Returns: Array an array of JSFile instances representing the contents of the specified folder that match the given filters.

Sample

getFolderContents(targetFolder, fileFilter, fileOption)

Returns an array of JSFile instances corresponding to content of the specified folder. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.

Parameters

  • String targetFolder File path.

  • Object fileFilter Filter or array of filters for files in folder.

  • Number fileOption 1=files, 2=dirs

Returns: Array an array of JSFile instances representing the contents of the specified folder that match the given filters.

Sample

getFolderContents(targetFolder, fileFilter, fileOption, visibleOption)

Returns an array of JSFile instances corresponding to content of the specified folder. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.

Parameters

  • String targetFolder File path.

  • Object fileFilter Filter or array of filters for files in folder.

  • Number fileOption 1=files, 2=dirs

  • Number visibleOption 1=visible, 2=nonvisible

Returns: Array an array of JSFile instances representing the contents of the specified folder that match the given filters.

Sample

getFolderContents(targetFolder, fileFilter, fileOption, visibleOption, lockedOption)

Returns an array of JSFile instances corresponding to content of the specified folder. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.

Parameters

  • String targetFolder File path.

  • Object fileFilter Filter or array of filters for files in folder.

  • Number fileOption 1=files, 2=dirs

  • Number visibleOption 1=visible, 2=nonvisible

  • Number lockedOption 1=locked, 2=nonlocked

Returns: Array an array of JSFile instances representing the contents of the specified folder that match the given filters.

Sample

getHomeFolder()

Returns a JSFile instance corresponding to the home folder of the logged in used.

Returns: JSFile a JSFile instance representing the home folder of the currently logged-in user.

Sample

getMaxUploadFileSize()

Returns the maximum allowed file size for uploads in KB. Defaults to servoy.webclient.maxuploadsize parameter from Admin page If this return 0 then this means there is no maximum set.

Returns: Number the maximum file size in KB

Sample

getModificationDate(fileOrPath)

Returns the modification date of a file.

Parameters

  • Object fileOrPath can be a (remote) JSFile or a local file path

Returns: Date the last modification date of the specified file, or null if the file is invalid.

Sample

getRemoteFolderContents(targetFolder)

Returns an array of JSFile instances corresponding to content of the specified folder on the server side. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.

Parameters

Returns: Array the array of file names

Sample

getRemoteFolderContents(targetFolder, fileFilter)

Returns an array of JSFile instances corresponding to content of the specified folder on the server side. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.

Parameters

  • JSFile targetFolder Folder as JSFile object.

  • Object fileFilter Filter or array of filters for files in folder.

Returns: Array the array of file names

Sample

getRemoteFolderContents(targetFolder, fileFilter, fileOption)

Returns an array of JSFile instances corresponding to content of the specified folder on the server side. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.

Parameters

  • JSFile targetFolder Folder as JSFile object.

  • Object fileFilter Filter or array of filters for files in folder.

  • Number fileOption 1=files, 2=dirs

Returns: Array the array of file names

Sample

getRemoteFolderContents(targetFolder, fileFilter, fileOption, visibleOption)

Returns an array of JSFile instances corresponding to content of the specified folder on the server side. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.

Parameters

  • JSFile targetFolder Folder as JSFile object.

  • Object fileFilter Filter or array of filters for files in folder.

  • Number fileOption 1=files, 2=dirs

  • Number visibleOption 1=visible, 2=nonvisible

Returns: Array the array of file names

Sample

getRemoteFolderContents(targetFolder, fileFilter, fileOption, visibleOption, lockedOption)

Returns an array of JSFile instances corresponding to content of the specified folder on the server side. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.

Parameters

  • JSFile targetFolder Folder as JSFile object.

  • Object fileFilter Filter or array of filters for files in folder.

  • Number fileOption 1=files, 2=dirs

  • Number visibleOption 1=visible, 2=nonvisible

  • Number lockedOption 1=locked, 2=nonlocked

Returns: Array the array of file names

Sample

getRemoteFolderContents(targetFolder)

Returns an array of JSFile instances corresponding to content of the specified folder on the server side. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.

Parameters

Returns: Array the array of file names

Sample

getRemoteFolderContents(targetFolder, fileFilter)

Returns an array of JSFile instances corresponding to content of the specified folder on the server side. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.

Parameters

  • String targetFolder Folder path.

  • Object fileFilter Filter or array of filters for files in folder.

Returns: Array the array of file names

Sample

getRemoteFolderContents(targetFolder, fileFilter, fileOption)

Returns an array of JSFile instances corresponding to content of the specified folder on the server side. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.

Parameters

  • String targetFolder Folder path.

  • Object fileFilter Filter or array of filters for files in folder.

  • Number fileOption 1=files, 2=dirs

Returns: Array the array of file names

Sample

getRemoteFolderContents(targetFolder, fileFilter, fileOption, visibleOption)

Returns an array of JSFile instances corresponding to content of the specified folder on the server side. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.

Parameters

  • String targetFolder Folder path.

  • Object fileFilter Filter or array of filters for files in folder.

  • Number fileOption 1=files, 2=dirs

  • Number visibleOption 1=visible, 2=nonvisible

Returns: Array the array of file names

Sample

getRemoteFolderContents(targetFolder, fileFilter, fileOption, visibleOption, lockedOption)

Returns an array of JSFile instances corresponding to content of the specified folder on the server side. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.

Parameters

  • String targetFolder Folder path.

  • Object fileFilter Filter or array of filters for files in folder.

  • Number fileOption 1=files, 2=dirs

  • Number visibleOption 1=visible, 2=nonvisible

  • Number lockedOption 1=locked, 2=nonlocked

Returns: Array the array of file names

Sample

moveFile(source, destination)

Moves the file from the source to the destination place. Returns true on success, false otherwise.

Parameters

Returns: Boolean true if the file was moved successfully; false otherwise.

Sample

openFile(file)

Opens the given local file.

The (server local) file will open inside the browser - if supported (sent using "Content-disposition: inline" HTTP header).

Parameters

  • JSFile file the local file to open. The file should exist and be accessible.

Returns: Boolean success status of the open operation

Sample

openFile(file, webClientTarget, webClientTargetOptions)

Opens the given local file.

The (server local) file will open inside the browser - if supported (sent using "Content-disposition: inline" HTTP header).

Parameters

  • JSFile file the local file to open. The file should exist and be accessible.

  • String webClientTarget Target frame or named dialog/window. For example "_self" to open in the same browser window, "_blank" for another browser window. By default "_blank" is used.

  • String webClientTargetOptions window options used when a new browser window is to be shown; see browser JS 'window.open(...)' documentation.

Returns: Boolean success status of the open operation

Sample

openFile(fileName, data, mimeType)

Opens the given data as a file.

The data will open as a file inside the browser - if supported (sent using "Content-disposition: inline" HTTP header).

Parameters

  • String fileName the name of the file that should open with the given data. Can be null.

  • Array data the file's binary content.

  • String mimeType can be left null, and is used for webclient only. Specify one of any valid mime types: https://developer.mozilla.org/en-US/docs/Properly_Configuring_Server_MIME_Types http://www.iana.org/assignments/media-types/media-types.xhtml http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7

Returns: Boolean success status of the open operation

Sample

openFile(fileName, data, mimeType, webClientTarget, webClientTargetOptions)

Opens the given data as a file.

The data will open as a file inside the browser - if supported (sent using "Content-disposition: inline" HTTP header).

Parameters

  • String fileName the name of the file that should open with the given data. Can be null.

  • Array data the file's binary content.

  • String mimeType can be left null, and is used for webclient only. Specify one of any valid mime types: https://developer.mozilla.org/en-US/docs/Properly_Configuring_Server_MIME_Types http://www.iana.org/assignments/media-types/media-types.xhtml http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7

  • String webClientTarget Target frame or named dialog/window. For example "_self" to open in the same browser window, "_blank" for another browser window. By default "_blank" is used.

  • String webClientTargetOptions window options used when a new browser window is to be shown; see browser JS 'window.open(...)' documentation.

Returns: Boolean success status of the open operation

Sample

readFile()

Reads all or part of the content from a binary file. If a file name is not specified, then a file selection dialog pops up for selecting a file. (Web Enabled only for a JSFile argument)

Returns: Array the content of the selected binary file as a byte array, or null if no file is selected or an error occurs.

Sample

readFile(file)

Reads all or part of the content from a binary file. If a file name is not specified, then a file selection dialog pops up for selecting a file. (Web Enabled only for a JSFile argument)

Parameters

Returns: Array the content of the specified binary file as a byte array, or null if the file cannot be read or an error occurs.

Sample

readFile(file, size)

Reads all or part of the content from a binary file. If a file name is not specified, then a file selection dialog pops up for selecting a file. (Web Enabled only for a JSFile argument)

Parameters

Returns: Array a byte array containing up to the specified number of bytes from the given binary file, or null if the file cannot be read or an error occurs.

Sample

readFile(file)

Reads all or part of the content from a binary file. If a file name is not specified, then a file selection dialog pops up for selecting a file. (Web Enabled only for a JSFile argument)

Parameters

Returns: Array the content of the binary file located at the specified file path as a byte array, or null if the file cannot be read or an error occurs.

Sample

readFile(file, size)

Reads all or part of the content from a binary file. If a file name is not specified, then a file selection dialog pops up for selecting a file. (Web Enabled only for a JSFile argument)

Parameters

  • String file the file path.

  • Number size Number of bytes to read.

Returns: Array a byte array containing up to the specified number of bytes from the binary file located at the given file path, or null if the file cannot be read or an error occurs.

Sample

readTXTFile()

Read all content from a text file. If a file name is not specified, then a file selection dialog pops up for selecting a file. The encoding can be also specified. (Web Enabled only for a JSFile argument)

Returns: String the content of the selected text file as a String, or null if no file was selected.

Sample

readTXTFile(file)

Read all content from a text file. If a file name is not specified, then a file selection dialog pops up for selecting a file. The encoding can be also specified. (Web Enabled only for a JSFile argument)

Parameters

Returns: String the content of the specified file path as a String, or null if the file is invalid.

Sample

readTXTFile(file, charsetname)

Read all content from a text file. If a file name is not specified, then a file selection dialog pops up for selecting a file. The encoding can be also specified. (Web Enabled only for a JSFile argument)

Parameters

Returns: String the content of the specified file as a String, or null if the file is invalid.

Sample

readTXTFile(file)

Read all content from a text file. If a file name is not specified, then a file selection dialog pops up for selecting a file. The encoding can be also specified. (Web Enabled only for a JSFile argument)

Parameters

Returns: String the content of the specified file path as a String, or null if the file is invalid.

Sample

readTXTFile(file, charsetname)

Read all content from a text file. If a file name is not specified, then a file selection dialog pops up for selecting a file. The encoding can be also specified. (Web Enabled only for a JSFile argument)

Parameters

Returns: String the content of the specified file path as a String, or null if the file is invalid.

Sample

setMaxUploadFileSize(size)

Sets the maximum allowed file size for uploads in KB. Defaults to servoy.webclient.maxuploadsize parameter from Admin page if the value is set to 0;

This sets the maximum file size uploads for the file plugin showFileOpenDialog but also for the file upload component.

Parameters

  • Number size the maximum file size in KB; 0 tis will use the default size from the admin page (servoy.webclient.maxuploadsize) > 0 max file size for upload (kb) overwriting the admin page value.

Returns: void

Sample

showFileOpenDialog(selectionMode, startDirectory, multiselect, filter, callbackfunction)

Shows a file open dialog. Filters can be applied on what type of files can be selected. (Web Enabled, you must set the callback method for this to work)

Parameters

  • Number selectionMode 0=both,1=Files,2=Dirs

  • JSFile startDirectory JSFile instance of default folder,null=default/previous

  • Boolean multiselect true/false

  • Object filter A filter or array of filters on the folder files.

  • Function callbackfunction A function that takes the (JSFile) array of the selected files as first argument

Returns: Object a JSFile or an array of JSFiles selected by the user, or null if no file was selected.

Sample

showFileOpenDialog(selectionMode, startDirectory, multiselect, filter, callbackfunction, title)

Shows a file open dialog. Filters can be applied on what type of files can be selected. (Web Enabled, you must set the callback method for this to work)

Parameters

  • Number selectionMode 0=both,1=Files,2=Dirs

  • JSFile startDirectory JSFile instance of default folder, null=default/previous

  • Boolean multiselect true/false

  • Object filter A filter or array of filters on the folder files.

  • Function callbackfunction A function that takes the (JSFile) array of the selected files as first argument

  • String title The tile of the dialog

Returns: Object a JSFile or an array of JSFiles selected by the user, or null if no file was selected.

Sample

showFileOpenDialog(selectionMode, startDirectory, multiselect, callbackfunction)

Shows a file open dialog. Filters can be applied on what type of files can be selected. (Web Enabled, you must set the callback method for this to work)

Parameters

  • Number selectionMode 0=both,1=Files,2=Dirs

  • JSFile startDirectory JSFile instance of default folder,null=default/previous

  • Boolean multiselect true/false

  • Function callbackfunction A function that takes the (JSFile) array of the selected files as first argument

Returns: Object a JSFile or an array of JSFiles selected by the user, or null if no file was selected.

Sample

showFileOpenDialog(selectionMode, startDirectory, callbackfunction)

Shows a file open dialog. Filters can be applied on what type of files can be selected. (Web Enabled, you must set the callback method for this to work)

Parameters

  • Number selectionMode 0=both,1=Files,2=Dirs

  • JSFile startDirectory JSFile instance of default folder,null=default/previous

  • Function callbackfunction A function that takes the (JSFile) array of the selected files as first argument

Returns: Object a JSFile or an array of JSFiles selected by the user, or null if no file was selected.

Sample

showFileOpenDialog(selectionMode, startDirectory, multiselect, filter, callbackfunction)

Shows a file open dialog. Filters can be applied on what type of files can be selected. (Web Enabled, you must set the callback method for this to work)

Parameters

  • Number selectionMode 0=both,1=Files,2=Dirs

  • String startDirectory Path to default folder,null=default/previous

  • Boolean multiselect true/false

  • Object filter A filter or array of filters on the folder files.

  • Function callbackfunction A function that takes the (JSFile) array of the selected files as first argument

Returns: Object a JSFile or an array of JSFiles selected by the user, or null if no file was selected.

Sample

showFileOpenDialog(selectionMode, startDirectory, multiselect, filter, callbackfunction, title)

Shows a file open dialog. Filters can be applied on what type of files can be selected. (Web Enabled, you must set the callback method for this to work)

Parameters

  • Number selectionMode 0=both,1=Files,2=Dirs

  • String startDirectory Path to default folder, null=default/previous

  • Boolean multiselect true/false

  • Object filter A filter or array of filters on the folder files.

  • Function callbackfunction A function that takes the (JSFile) array of the selected files as first argument

  • String title The tile of the dialog

Returns: Object a JSFile or an array of JSFiles selected by the user, or null if no file was selected.

Sample

showFileOpenDialog(selectionMode, startDirectory, multiselect, callbackfunction)

Shows a file open dialog. Filters can be applied on what type of files can be selected. (Web Enabled, you must set the callback method for this to work)

Parameters

  • Number selectionMode 0=both,1=Files,2=Dirs

  • String startDirectory Path to default folder,null=default/previous

  • Boolean multiselect true/false

  • Function callbackfunction A function that takes the (JSFile) array of the selected files as first argument

Returns: Object a JSFile or an array of JSFiles selected by the user, or null if no file was selected.

Sample

showFileOpenDialog(selectionMode, startDirectory, callbackfunction)

Shows a file open dialog. Filters can be applied on what type of files can be selected. (Web Enabled, you must set the callback method for this to work)

Parameters

  • Number selectionMode 0=both,1=Files,2=Dirs

  • String startDirectory Path to default folder,null=default/previous

  • Function callbackfunction A function that takes the (JSFile) array of the selected files as first argument

Returns: Object a JSFile or an array of JSFiles selected by the user, or null if no file was selected.

Sample

showFileOpenDialog(selectionMode, callbackfunction)

Shows a file open dialog. Filters can be applied on what type of files can be selected. (Web Enabled, you must set the callback method for this to work)

Parameters

  • Number selectionMode 0=both,1=Files,2=Dirs

  • Function callbackfunction A function that takes the (JSFile) array of the selected files as first argument

Returns: Object a JSFile or an array of JSFiles selected by the user, or null if no file was selected.

Sample

showFileOpenDialog(callbackfunction)

Shows a file open dialog. Filters can be applied on what type of files can be selected. (Web Enabled, you must set the callback method for this to work)

Parameters

  • Function callbackfunction A function that takes the (JSFile) array of the selected files as first argument

Returns: Object a JSFile or an array of JSFiles selected by the user, or null if no file was selected.

Sample

streamFile(file)

Stream the given file(path) to the browser with content-disposition:attachment This will not load in the file fully into memory but only stream it right from disk. This can be any filepath on the server, but only the simple file name is exposed as the content disposition header filename. This will throw an exception if anything goes wrong, like the given file is not valid/found.

Parameters

  • Object file A path string, JSFile or RemoteFile

Returns: void

streamFile(file, contentDisposition)

String the given file(path) to the browser you can provide the content disposition how this should be send (inline or as an attachment) This will not load in the file fully into memory but only stream it right from disk. This can be any filepath on the server, but only the simple file name is exposed. This will throw an exception if anything goes wrong, like the given file is not valid/found.

Parameters

  • Object file A path string, JSFile or RemoteFile

  • String contentDisposition can be 'inline' or 'attachment'

Returns: void

streamFile(file, contentDisposition, browserTarget)

String the given file(path) to the browser you can provide the content disposition how this should be send (inline or as an attachment) This will not load in the file fully into memory but only stream it right from disk. This can be any filepath on the server, but only the simple file name is exposed. This will throw an exception if anything goes wrong, like the given file is not valid/found. Give the browser target if you want to open the file inside another tab, most usefull in 'inline' content disposition mode.

Parameters

  • Object file A path string, JSFile or RemoteFile

  • String contentDisposition can be 'inline' or 'attachment'

  • String browserTarget _blank or a specific name to open this in a differnt tab (really only usefull in inline mode)

Returns: void

trackFileForDeletion(file)

If the client's solution is closed, the file given to this method will be deleted. This can be a remote or local file.

This can be used to have temp files within a client that will be cleaned up when the solution is closed. So they live as long as the client has its solution open.

Parameters

Returns: void

Sample

writeFile(file, data)

Writes the given file to disk.

If "file" is a String (like 'mypdffile.pdf' to hint the browser what it is) the user will get prompted by the browser to save the file (sent using "Content-disposition: attachment" HTTP header). If it is a JSFile instance in this case it will be saved as a file on the server.

Parameters

  • JSFile file a local JSFile

  • Array data the data to be written

Returns: Boolean true if the binary data was successfully written to the file; false otherwise

Sample

writeFile(file, data, mimeType)

Writes the given file to disk.

If "file" is a String (like 'mypdffile.pdf' to hint the browser what it is) the user will get prompted by the browser to save the file (sent using "Content-disposition: attachment" HTTP header). If it is a JSFile instance in this case it will be saved as a file on the server.

Parameters

  • JSFile file a local JSFile

  • Array data the data to be written

  • String mimeType the mime type (used in Web-Client)

Returns: Boolean true if the binary data was successfully written to the file; false otherwise.

Sample

writeFile(file, data)

Writes the given file to disk.

If "file" is a String (like 'mypdffile.pdf' to hint the browser what it is) the user will get prompted by the browser to save the file (sent using "Content-disposition: attachment" HTTP header). If it is a JSFile instance in this case it will be saved as a file on the server.

Parameters

  • String file the file path as a String

  • Array data the data to be written

Returns: Boolean true if the binary data was successfully written to the file path; false otherwise.

Sample

writeFile(file, data, mimeType)

Writes the given file to disk.

If "file" is a String (like 'mypdffile.pdf' to hint the browser what it is) the user will get prompted by the browser to save the file (sent using "Content-disposition: attachment" HTTP header). If it is a JSFile instance in this case it will be saved as a file on the server.

Parameters

  • String file the file path as a String

  • Array data the data to be written

  • String mimeType the mime type (used in Web-Client)

Returns: Boolean true if the binary data was successfully written to the file path; false otherwise.

Sample

writeTXTFile(file, text_data)

Writes data into a text file. (Web Enabled: file parameter can be a string 'mytextfile.txt' to hint the browser what it is, if it is a JSFile instance it will be saved on the server)

Parameters

Returns: Boolean true if the text data was successfully written to the file; false otherwise.

Sample

writeTXTFile(file, text_data, charsetname)

Writes data into a text file. (Web Enabled: file parameter can be a string 'mytextfile.txt' to hint the browser what it is, if it is a JSFile instance it will be saved on the server)

Parameters

Returns: Boolean true if the text data was successfully written to the specified file; false otherwise.

Sample

writeTXTFile(file, text_data, charsetname, mimeType)

Writes data into a text file. (Web Enabled: file parameter can be a string 'mytextfile.txt' to hint the browser what it is, if it is a JSFile instance it will be saved on the server)

Parameters

  • JSFile file JSFile

  • String text_data Text to be written.

  • String charsetname Charset name.

  • String mimeType Content type (used only on web).

Returns: Boolean true if the text data was successfully written to the specified file; false otherwise.

Sample

writeTXTFile(file, text_data)

Writes data into a text file. (Web Enabled: file parameter can be a string 'mytextfile.txt' to hint the browser what it is, if it is a JSFile instance it will be saved on the server)

Parameters

  • String file The file path.

  • String text_data Text to be written.

Returns: Boolean true if the text data was successfully written to the specified file path; false otherwise.

Sample

writeTXTFile(file, text_data, charsetname)

Writes data into a text file. (Web Enabled: file parameter can be a string 'mytextfile.txt' to hint the browser what it is, if it is a JSFile instance it will be saved on the server)

Parameters

  • String file The file path.

  • String text_data Text to be written.

  • String charsetname Charset name.

Returns: Boolean true if the text data was successfully written to the specified file path; false otherwise.

Sample

writeTXTFile(file, text_data, charsetname, mimeType)

Writes data into a text file. (Web Enabled: file parameter can be a string 'mytextfile.txt' to hint the browser what it is, if it is a JSFile instance it will be saved on the server)

Parameters

  • String file The file path.

  • String text_data Text to be written.

  • String charsetname Charset name.

  • String mimeType Content type (used only on web).

Returns: Boolean true if the text data was successfully written to the specified file path; false otherwise.

Sample

writeXMLFile(file, xml_data)

Writes data into an XML file. The file is saved with the encoding specified by the XML itself. (Web Enabled: file parameter can be a string 'myxmlfile.xml' to hint the browser what it is, if it is a JSFile instance it will be saved on the server)

Parameters

  • JSFile file a local JSFile

  • String xml_data the xml data to write

Returns: Boolean true if the XML data was successfully written to the specified file; false otherwise.

Sample

writeXMLFile(file, xml_data, encoding)

Writes data into an XML file. The file is saved with the encoding specified by the XML itself. (Web Enabled: file parameter can be a string 'myxmlfile.xml' to hint the browser what it is, if it is a JSFile instance it will be saved on the server)

Parameters

  • JSFile file a local JSFile

  • String xml_data the xml data to write

  • String encoding the specified encoding

Returns: Boolean true if the XML data was successfully written to the file; false otherwise.

Sample

writeXMLFile(file, xml_data)

Writes data into an XML file. The file is saved with the encoding specified by the XML itself. (Web Enabled: file parameter can be a string 'myxmlfile.xml' to hint the browser what it is, if it is a JSFile instance it will be saved on the server)

Parameters

  • String file the file path as a String

  • String xml_data the xml data to write

Returns: Boolean true if the XML data was successfully written to the specified file path; false otherwise.

Sample

writeXMLFile(file, xml_data, encoding)

Writes data into an XML file. The file is saved with the encoding specified by the XML itself. (Web Enabled: file parameter can be a string 'myxmlfile.xml' to hint the browser what it is, if it is a JSFile instance it will be saved on the server)

Parameters

  • String file the file path as a String

  • String xml_data the xml data to write

  • String encoding the specified encoding

Returns: Boolean true if the XML data was successfully written to the specified file path; false otherwise.

Sample


Last updated

Was this helpful?