Child pages
  • file

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin
Hidden
DO NOT EDIT THE CONTENT OF THIS PAGE DIRECTLY, UNLESS YOU KNOW WHAT YOU'RE DOING.		THE STRUCTURE OF THE CONTENT IS VITAL IN BEING ABLE TO EXTRACT CHANGES FROM THE PAGE AND MERGE THEM BACK INTO SERVOY SOURCE

The File plugin provides functionality to work with files.

Main features are:

  • Creating temporary files
  • Reading from and writing to the filesystem
  • Retrieving information on files and directories on the file system
  • Streaming files between the Smart Client and the Server (and vise versa)

When using the File plugin, it's important to take into account the differences and compatibility between different clients:

  • Interacting with the file system through the plugin in a Smart Client happens client-side, so on the machine where the Smart Client is launched. On all other clients (Web, Headless & Batchprocessor), the operations are performed on the Server.
  • All showXxxxDialog(...) functions interact with the user through a UI. These function can only be used in Clients that provide a UI, like the Smart and Web Client.
  • The showXxxxDialog(...) functions, when used in the Web Client, have certain limitations due to being operated in a browser. Browser security (currently) limits interaction with the local file system, except for single file select operations initiated by the user clicking a button.

HTML Table
classservoy sReturnTypes
Table Row (tr)
styleheight: 30px;
Table Head (th)
Return Types
Table Row (tr)
Table Cell (td)
Span
classsWordList
JSFile

HTML Table
classservoy sSummery
Colgroup Tag
Column
padding0px
width80px

Column

Table Row (tr)
styleheight: 30px;
Table Head (th)
colspan2
Server Property Summery
Table Body (tbody)
Table Row (tr)
Table Cell (td)

Table Cell (td)
#servoy.FileServerService.defaultFolder

HTML Table
classservoy sSummery
Colgroup Tag
Column
padding0px
width80px

Column

Table Row (tr)
styleheight: 30px;
Table Head (th)
colspan2
Method Summery
Table Body (tbody)
Table Row (tr)
Table Cell (td)
Boolean
Table Cell (td)
#appendToTXTFile(file/fileName, text, [encoding])
Appends data into a text file.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
JSFile
Table Cell (td)
#convertToJSFile(file)
Returns a JSFile instance corresponding to an alternative representation of a file (for example a string).
Table Body (tbody)
Table Row (tr)
Table Cell (td)
JSFile
Table Cell (td)
#convertToRemoteJSFile(serverPath)
Returns the JSFile object of a server file, given its path (relative the default server location)
Table Body (tbody)
Table Row (tr)
Table Cell (td)
Boolean
Table Cell (td)
#copyFile(sourceFile, destinationFile)
Copies the sourcefile to the destination file.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
Boolean
Table Cell (td)
#copyFolder(sourceFolder, destinationFolder)
Copies the sourcefolder to the destination folder, recursively.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
JSFile
Table Cell (td)
#createFile(targetFile)
Creates a JSFile instance.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
Boolean
Table Cell (td)
#createFolder(targetFolder)
Creates a folder on disk.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
JSFile
Table Cell (td)
#createTempFile(filePrefix, fileSuffix)
Creates a temporary file on disk.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
Boolean
Table Cell (td)
#deleteFile(targetFile)
Removes a file from disk.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
Boolean
Table Cell (td)
#deleteFolder(targetFolder, showWarning)
Deletes a folder from disk recursively.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
JSFile
Table Cell (td)
#getDesktopFolder()
Returns a JSFile instance that corresponds to the Desktop folder of the currently logged in user.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
JSFile[]
Table Cell (td)
#getDiskList()
Returns an Array of JSFile instances correponding to the file system root folders.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
Number
Table Cell (td)
#getFileSize(targetFile)
Returns the size of the specified file.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
JSFile[]
Table Cell (td)
#getFolderContents(targetFolder, [fileFilter], [fileOption(1=files,2=dirs)], [visibleOption(1=visible,2=nonvisible)], [lockedOption(1=locked,2=nonlocked)])
Returns an array of JSFile instances corresponding to content of the specified folder.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
JSFile
Table Cell (td)
#getHomeDirectory()
Returns a JSFile instance corresponding to the home folder of the logged in used.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
Date
Table Cell (td)
#getModificationDate(targetFile)
Returns the modification date of a file.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
JSFile[]
Table Cell (td)
#getRemoteList(serverFolder/serverFolderPath, [filesOnly])
Retrieves a list of files existing in a folder on the server side (in the path provided, relative to the default server location)
Table Body (tbody)
Table Row (tr)
Table Cell (td)
Boolean
Table Cell (td)
#moveFile(sourceFile, destinationFile)
Moves the file from the source to the destination place.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
byte[]
Table Cell (td)
#readFile([file], [size])
Reads all or part of the content from a binary file.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
String
Table Cell (td)
#readTXTFile([file], [charsetname])
Read all content from a text file.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
JSFile
Table Cell (td)
#showDirectorySelectDialog([directory suggestion], [dialog title text])
Shows a directory selector dialog.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
Object
Table Cell (td)
#showFileOpenDialog([selectionMode(0=both,1=Files,2=Dirs)], [startDirectory(null=default/previous)], [multiselect(true/false)], [filterarray], [callbackmethod], [dialog title text])
Shows a file open dialog.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
JSFile
Table Cell (td)
#showFileSaveDialog([fileName/dir suggestion], [dialog title text])
Shows a file save dialog.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
#streamFilesFromServer(file/fileName|fileArray/fileNameArray, serverFile/serverFileName|serverFileArray/serverFileNameArray, [callbackFunction])
Streams a file or an array of files from the server in a background task to a file (or files) on the client.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
#streamFilesToServer(file/fileName|fileArray/fileNameArray, [serverFile/serverFileName|serverFileArray/serverFileNameArray], [callbackFunction])
Streams a file or an array of files to the server in a background task - with optional relative path(s)/(new) name(s).
Table Body (tbody)
Table Row (tr)
Table Cell (td)
Boolean
Table Cell (td)
#writeFile(file, binary_data, [mimeType])
Writes data into a binary file.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
Boolean
Table Cell (td)
#writeTXTFile(file, text_data, [charsetname], [mimeType])
Writes data into a text file.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
Boolean
Table Cell (td)
#writeXMLFile(file, xml_data)
Writes data into an XML file.

HTML Table
idserverProperty
classservoy sDetail
Colgroup Tag
Column
padding0px
width100%

Table Row (tr)
styleheight: 30px;
Table Head (th)
colspan1
Server Property Details
Table Body (tbody)
idservoy.FileServerService.defaultFolder
classnode
Table Row (tr)
idname
Table Cell (td)
servoy.FileServerService.defaultFolder
Table Row (tr)
iddes
Table Cell (td)
Set the default folder path to save files sent by client (will default to /uploads/)
Table Row (tr)
classlastDetailRow
Table Cell (td)


HTML Table
idfunction
classservoy sDetail
Colgroup Tag
Column
padding0px
width100%

Table Row (tr)
styleheight: 30px;
Table Head (th)
colspan1
Method Details
Table Body (tbody)
idappendToTXTFile
classnode
Table Row (tr)
idname
Table Cell (td)
appendToTXTFile
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
Boolean
Span
stylefloat: left; font-weight: bold;
idiets
appendToTXTFile
Span
stylefloat: left;
idiets
(file/fileName, text, [encoding])
Table Row (tr)
iddes
Table Cell (td)
Appends data into a text file.
Table Row (tr)
idprs
Table Cell (td)
Parameters
file/fileName
text
[encoding]
Table Row (tr)
idret
Table Cell (td)
Returns
Boolean
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
// append some text to a text file:
	var ok = plugins.file.appendToTXTFile('myTextFile.txt', '\nMy fantastic new line of text\n');
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idconvertToJSFile
classnode
Table Row (tr)
idname
Table Cell (td)
convertToJSFile
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
JSFile
Span
stylefloat: left; font-weight: bold;
idiets
convertToJSFile
Span
stylefloat: left;
idiets
(file)
Table Row (tr)
iddes
Table Cell (td)
Returns a JSFile instance corresponding to an alternative representation of a file (for example a string).
Table Row (tr)
idprs
Table Cell (td)
Parameters
file
Table Row (tr)
idret
Table Cell (td)
Returns
JSFile
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
var f = plugins.file.convertToJSFile("story.txt");
if (f.canRead())
	application.output("File can be read.");
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idconvertToRemoteJSFile
classnode
Table Row (tr)
idname
Table Cell (td)
convertToRemoteJSFile
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
JSFile
Span
stylefloat: left; font-weight: bold;
idiets
convertToRemoteJSFile
Span
stylefloat: left;
idiets
(serverPath)
Table Row (tr)
iddes
Table Cell (td)
Returns the JSFile object of a server file, given its path (relative the default server location)
Table Row (tr)
idprs
Table Cell (td)
Parameters
serverPath
Table Row (tr)
idret
Table Cell (td)
Returns
JSFile
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
var f = plugins.file.convertToRemoteJSFile('/story.txt');
if (f && f.canRead())
	application.output('File can be read.');
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idcopyFile
classnode
Table Row (tr)
idname
Table Cell (td)
copyFile
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
Boolean
Span
stylefloat: left; font-weight: bold;
idiets
copyFile
Span
stylefloat: left;
idiets
(sourceFile, destinationFile)
Table Row (tr)
iddes
Table Cell (td)
Copies the sourcefile to the destination file. Returns true if the copy succeeds, false if any error occurs.
Table Row (tr)
idprs
Table Cell (td)
Parameters
sourceFile
destinationFile
Table Row (tr)
idret
Table Cell (td)
Returns
Boolean
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
// Copy based on file names.
if (!plugins.file.copyFile("story.txt", "story.txt.copy"))
	application.output("Copy failed.");
// Copy based on JSFile instances.
var f = plugins.file.createFile("story.txt");
var fcopy = plugins.file.createFile("story.txt.copy2");
if (!plugins.file.copyFile(f, fcopy))
	application.output("Copy failed.");
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idcopyFolder
classnode
Table Row (tr)
idname
Table Cell (td)
copyFolder
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
Boolean
Span
stylefloat: left; font-weight: bold;
idiets
copyFolder
Span
stylefloat: left;
idiets
(sourceFolder, destinationFolder)
Table Row (tr)
iddes
Table Cell (td)
Copies the sourcefolder to the destination folder, recursively. Returns true if the copy succeeds, false if any error occurs.
Table Row (tr)
idprs
Table Cell (td)
Parameters
sourceFolder
destinationFolder
Table Row (tr)
idret
Table Cell (td)
Returns
Boolean
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
// Copy folder based on names.
if (!plugins.file.copyFolder("stories", "stories_copy"))
	application.output("Folder copy failed.");
// Copy folder based on JSFile instances.
var d = plugins.file.createFile("stories");
var dcopy = plugins.file.createFile("stories_copy_2");
if (!plugins.file.copyFolder(d, dcopy))
	application.output("Folder copy failed.");
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idcreateFile
classnode
Table Row (tr)
idname
Table Cell (td)
createFile
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
JSFile
Span
stylefloat: left; font-weight: bold;
idiets
createFile
Span
stylefloat: left;
idiets
(targetFile)
Table Row (tr)
iddes
Table Cell (td)
Creates a JSFile instance. Does not create the file on disk.
Table Row (tr)
idprs
Table Cell (td)
Parameters
targetFile
Table Row (tr)
idret
Table Cell (td)
Returns
JSFile
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
// Create the JSFile instance based on the file name.
var f = plugins.file.createFile("newfile.txt");
// Create the file on disk.
if (!f.createNewFile())
	application.output("The file could not be created.");
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idcreateFolder
classnode
Table Row (tr)
idname
Table Cell (td)
createFolder
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
Boolean
Span
stylefloat: left; font-weight: bold;
idiets
createFolder
Span
stylefloat: left;
idiets
(targetFolder)
Table Row (tr)
iddes
Table Cell (td)
Creates a folder on disk. Returns true if the folder is successfully created, false if any error occurs.
Table Row (tr)
idprs
Table Cell (td)
Parameters
targetFolder
Table Row (tr)
idret
Table Cell (td)
Returns
Boolean
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
var d = plugins.file.convertToJSFile("newfolder");
if (!plugins.file.createFolder(d))
	application.output("Folder could not be created.");
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idcreateTempFile
classnode
Table Row (tr)
idname
Table Cell (td)
createTempFile
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
JSFile
Span
stylefloat: left; font-weight: bold;
idiets
createTempFile
Span
stylefloat: left;
idiets
(filePrefix, fileSuffix)
Table Row (tr)
iddes
Table Cell (td)
Creates a temporary file on disk. A prefix and an extension are specified and they will be part of the file name.
Table Row (tr)
idprs
Table Cell (td)
Parameters
filePrefix
fileSuffix
Table Row (tr)
idret
Table Cell (td)
Returns
JSFile
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
var tempFile = plugins.file.createTempFile('myfile','.txt');
application.output('Temporary file created as: ' + tempFile.getAbsolutePath());
plugins.file.writeTXTFile(tempFile, 'abcdefg');
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
iddeleteFile
classnode
Table Row (tr)
idname
Table Cell (td)
deleteFile
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
Boolean
Span
stylefloat: left; font-weight: bold;
idiets
deleteFile
Span
stylefloat: left;
idiets
(targetFile)
Table Row (tr)
iddes
Table Cell (td)
Removes a file from disk. Returns true on success, false otherwise.
Table Row (tr)
idprs
Table Cell (td)
Parameters
targetFile
Table Row (tr)
idret
Table Cell (td)
Returns
Boolean
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
if (plugins.file.deleteFile('story.txt'))
	application.output('File deleted.');
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
iddeleteFolder
classnode
Table Row (tr)
idname
Table Cell (td)
deleteFolder
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
Boolean
Span
stylefloat: left; font-weight: bold;
idiets
deleteFolder
Span
stylefloat: left;
idiets
(targetFolder, showWarning)
Table Row (tr)
iddes
Table Cell (td)
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.
Table Row (tr)
idprs
Table Cell (td)
Parameters
targetFolder
showWarning
Table Row (tr)
idret
Table Cell (td)
Returns
Boolean
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
if (plugins.file.deleteFolder('stories', true))
	application.output('Folder deleted.');
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idgetDesktopFolder
classnode
Table Row (tr)
idname
Table Cell (td)
getDesktopFolder
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
JSFile
Span
stylefloat: left; font-weight: bold;
idiets
getDesktopFolder
Span
stylefloat: left;
idiets
()
Table Row (tr)
iddes
Table Cell (td)
Returns a JSFile instance that corresponds to the Desktop folder of the currently logged in user.
Table Row (tr)
idret
Table Cell (td)
Returns
JSFile
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
var d = plugins.file.getDesktopFolder();
application.output('desktop folder is: ' + d.getAbsolutePath());
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idgetDiskList
classnode
Table Row (tr)
idname
Table Cell (td)
getDiskList
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
JSFile[]
Span
stylefloat: left; font-weight: bold;
idiets
getDiskList
Span
stylefloat: left;
idiets
()
Table Row (tr)
iddes
Table Cell (td)
Returns an Array of JSFile instances correponding to the file system root folders.
Table Row (tr)
idret
Table Cell (td)
Returns
JSFile[]
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
var roots = plugins.file.getDiskList();
for (var i = 0; i < roots.length; i++)
	application.output(roots[i].getAbsolutePath());
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idgetFileSize
classnode
Table Row (tr)
idname
Table Cell (td)
getFileSize
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
Number
Span
stylefloat: left; font-weight: bold;
idiets
getFileSize
Span
stylefloat: left;
idiets
(targetFile)
Table Row (tr)
iddes
Table Cell (td)
Returns the size of the specified file.
Table Row (tr)
idprs
Table Cell (td)
Parameters
targetFile
Table Row (tr)
idret
Table Cell (td)
Returns
Number
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
var f = plugins.file.convertToJSFile('story.txt');
application.output('file size: ' + plugins.file.getFileSize(f));
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idgetFolderContents
classnode
Table Row (tr)
idname
Table Cell (td)
getFolderContents
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
JSFile[]
Span
stylefloat: left; font-weight: bold;
idiets
getFolderContents
Span
stylefloat: left;
idiets
(targetFolder, [fileFilter], [fileOption(1=files,2=dirs)], [visibleOption(1=visible,2=nonvisible)], [lockedOption(1=locked,2=nonlocked)])
Table Row (tr)
iddes
Table Cell (td)
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.
Table Row (tr)
idprs
Table Cell (td)
Parameters
targetFolder
[fileFilter]
[fileOption(1=files,2=dirs)]
[visibleOption(1=visible,2=nonvisible)]
[lockedOption(1=locked,2=nonlocked)]
Table Row (tr)
idret
Table Cell (td)
Returns
JSFile[]
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
var files = plugins.file.getFolderContents('stories', '.txt');
for (var i=0; i<files.length; i++)
	application.output(files[i].getAbsolutePath());
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idgetHomeDirectory
classnode
Table Row (tr)
idname
Table Cell (td)
getHomeDirectory
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
JSFile
Span
stylefloat: left; font-weight: bold;
idiets
getHomeDirectory
Span
stylefloat: left;
idiets
()
Table Row (tr)
iddes
Table Cell (td)
Returns a JSFile instance corresponding to the home folder of the logged in used.
Table Row (tr)
idret
Table Cell (td)
Returns
JSFile
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
var d = plugins.file.getHomeDirectory();
application.output('home folder: ' + d.getAbsolutePath());
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idgetModificationDate
classnode
Table Row (tr)
idname
Table Cell (td)
getModificationDate
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
Date
Span
stylefloat: left; font-weight: bold;
idiets
getModificationDate
Span
stylefloat: left;
idiets
(targetFile)
Table Row (tr)
iddes
Table Cell (td)
Returns the modification date of a file.
Table Row (tr)
idprs
Table Cell (td)
Parameters
targetFile
Table Row (tr)
idret
Table Cell (td)
Returns
Date
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
var f = plugins.file.convertToJSFile('story.txt');
application.output('last changed: ' + plugins.file.getModificationDate(f));
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idgetRemoteList
classnode
Table Row (tr)
idname
Table Cell (td)
getRemoteList
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
JSFile[]
Span
stylefloat: left; font-weight: bold;
idiets
getRemoteList
Span
stylefloat: left;
idiets
(serverFolder/serverFolderPath, [filesOnly])
Table Row (tr)
iddes
Table Cell (td)
Retrieves a list of files existing in a folder on the server side (in the path provided, relative to the default server location)
Table Row (tr)
idprs
Table Cell (td)
Parameters
serverFolder/serverFolderPath
[filesOnly]
Table Row (tr)
idret
Table Cell (td)
Returns
JSFile[]
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idmoveFile
classnode
Table Row (tr)
idname
Table Cell (td)
moveFile
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
Boolean
Span
stylefloat: left; font-weight: bold;
idiets
moveFile
Span
stylefloat: left;
idiets
(sourceFile, destinationFile)
Table Row (tr)
iddes
Table Cell (td)
Moves the file from the source to the destination place. Returns true on success, false otherwise.
Table Row (tr)
idprs
Table Cell (td)
Parameters
sourceFile
destinationFile
Table Row (tr)
idret
Table Cell (td)
Returns
Boolean
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
// Move file based on names.
if (!plugins.file.moveFile('story.txt','story.txt.new'))
	application.output('File move failed.');
// Move file based on JSFile instances.
var f = plugins.file.convertToJSFile('story.txt.new');
var fmoved = plugins.file.convertToJSFile('story.txt');
if (!plugins.file.moveFile(f, fmoved))
	application.output('File move back failed.');
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idreadFile
classnode
Table Row (tr)
idname
Table Cell (td)
readFile
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
byte[]
Span
stylefloat: left; font-weight: bold;
idiets
readFile
Span
stylefloat: left;
idiets
([file], [size])
Table Row (tr)
iddes
Table Cell (td)
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)
Table Row (tr)
idprs
Table Cell (td)
Parameters
[file]
[size]
Table Row (tr)
idret
Table Cell (td)
Returns
byte[]
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
// Read all content from the file.
var bytes = plugins.file.readFile('big.jpg');
application.output('file size: ' + bytes.length);
// Read only the first 1KB from the file.
var bytesPartial = plugins.file.readFile('big.jpg', 1024);
application.output('partial file size: ' + bytesPartial.length);
// Read all content from a file selected from the file open dialog.
var bytesUnknownFile = plugins.file.readFile();
application.output('unknown file size: ' + bytesUnknownFile.length);
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idreadTXTFile
classnode
Table Row (tr)
idname
Table Cell (td)
readTXTFile
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
String
Span
stylefloat: left; font-weight: bold;
idiets
readTXTFile
Span
stylefloat: left;
idiets
([file], [charsetname])
Table Row (tr)
iddes
Table Cell (td)
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)
Table Row (tr)
idprs
Table Cell (td)
Parameters
[file]
[charsetname]
Table Row (tr)
idret
Table Cell (td)
Returns
String
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
// Read content from a known text file.
var txt = plugins.file.readTXTFile('story.txt');
application.output(txt);
// Read content from a text file selected from the file open dialog.
var txtUnknown = plugins.file.readTXTFile();
application.output(txtUnknown);
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idshowDirectorySelectDialog
classnode
Table Row (tr)
idname
Table Cell (td)
showDirectorySelectDialog
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
JSFile
Span
stylefloat: left; font-weight: bold;
idiets
showDirectorySelectDialog
Span
stylefloat: left;
idiets
([directory suggestion], [dialog title text])
Table Row (tr)
iddes
Table Cell (td)
Shows a directory selector dialog.
Table Row (tr)
idprs
Table Cell (td)
Parameters
[directory suggestion]
[dialog title text]
Table Row (tr)
idret
Table Cell (td)
Returns
JSFile
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
var dir = plugins.file.showDirectorySelectDialog();
application.output("you've selected folder: " + dir.getAbsolutePath());
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idshowFileOpenDialog
classnode
Table Row (tr)
idname
Table Cell (td)
showFileOpenDialog
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
Object
Span
stylefloat: left; font-weight: bold;
idiets
showFileOpenDialog
Span
stylefloat: left;
idiets
([selectionMode(0=both,1=Files,2=Dirs)], [startDirectory(null=default/previous)], [multiselect(true/false)], [filterarray], [callbackmethod], [dialog title text])
Table Row (tr)
iddes
Table Cell (td)
Shows a file open dialog. Filters can be applied on what type of files can be selected. (Web Enabled)
Table Row (tr)
idprs
Table Cell (td)
Parameters
[selectionMode(0=both,1=Files,2=Dirs)]
[startDirectory(null=default/previous)]
[multiselect(true/false)]
[filterarray]
[callbackmethod]
[dialog title text]
Table Row (tr)
idret
Table Cell (td)
Returns
Object
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
// This selects only files ('1'), previous dir must be used ('null'), no multiselect ('false') and
// the filter "JPG and GIF" should be used: ('new Array("JPG and GIF","jpg","gif")').
var file = plugins.file.showFileOpenDialog(1, null, false, new Array("JPG and GIF","jpg","gif"));
application.output("you've selected file: " + file.getAbsolutePath());
//for the web you have to give a callback function that has a JSFile array as its first argument (also works in smart), other options can be set but are not used in the webclient (yet)
var file = plugins.file.showFileOpenDialog(myCallbackMethod)
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idshowFileSaveDialog
classnode
Table Row (tr)
idname
Table Cell (td)
showFileSaveDialog
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
JSFile
Span
stylefloat: left; font-weight: bold;
idiets
showFileSaveDialog
Span
stylefloat: left;
idiets
([fileName/dir suggestion], [dialog title text])
Table Row (tr)
iddes
Table Cell (td)
Shows a file save dialog.
Table Row (tr)
idprs
Table Cell (td)
Parameters
[fileName/dir suggestion]
[dialog title text]
Table Row (tr)
idret
Table Cell (td)
Returns
JSFile
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
var file = plugins.file.showFileSaveDialog();
application.output("you've selected file: " + file.getAbsolutePath());
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idstreamFilesFromServer
classnode
Table Row (tr)
idname
Table Cell (td)
streamFilesFromServer
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
void
Span
stylefloat: left; font-weight: bold;
idiets
streamFilesFromServer
Span
stylefloat: left;
idiets
(file/fileName|fileArray/fileNameArray, serverFile/serverFileName|serverFileArray/serverFileNameArray, [callbackFunction])
Table Row (tr)
iddes
Table Cell (td)
Streams a file or an array of files from the server in a background task to a file (or files) on the client. If provided, calls back a Servoy function when done
Table Row (tr)
idprs
Table Cell (td)
Parameters
file/fileName|fileArray/fileNameArray
serverFile/serverFileName|serverFileArray/serverFileNameArray
[callbackFunction]
Table Row (tr)
idret
Table Cell (td)
Returns
void
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
// transfer the first file of the default server folder to a chosen file on the client
	var dir = plugins.file.getDesktopFolder();
	var file = plugins.file.showFileSaveDialog(dir,'Save file to');
	if (file) {
		var list = plugins.file.getRemoteList('/', true);
		if (list && list.length > 0) {
			plugins.file.streamFilesFromServer(file, list[0], callbackFunction);
		}
	}
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idstreamFilesToServer
classnode
Table Row (tr)
idname
Table Cell (td)
streamFilesToServer
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
void
Span
stylefloat: left; font-weight: bold;
idiets
streamFilesToServer
Span
stylefloat: left;
idiets
(file/fileName|fileArray/fileNameArray, [serverFile/serverFileName|serverFileArray/serverFileNameArray], [callbackFunction])
Table Row (tr)
iddes
Table Cell (td)
Streams a file or an array of files to the server in a background task - with optional relative path(s)/(new) name(s). If provided, calls back a Servoy function when done
Table Row (tr)
idprs
Table Cell (td)
Parameters
file/fileName|fileArray/fileNameArray
[serverFile/serverFileName|serverFileArray/serverFileNameArray]
[callbackFunction]
Table Row (tr)
idret
Table Cell (td)
Returns
void
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
// send one file:
	var file = plugins.file.showFileOpenDialog( 1, null, false, null, null, 'Choose a file to transfer' );
	if (file) {
		plugins.file.streamFilesToServer( file, callbackFunction );
	}
	// send an array of files:
	var folder = plugins.file.showDirectorySelectDialog();
	if (folder) {
		var files = plugins.file.getFolderContents(folder);
		if (files) {
			plugins.file.streamFilesToServer( files, callbackFunction );
		}
	}
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idwriteFile
classnode
Table Row (tr)
idname
Table Cell (td)
writeFile
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
Boolean
Span
stylefloat: left; font-weight: bold;
idiets
writeFile
Span
stylefloat: left;
idiets
(file, binary_data, [mimeType])
Table Row (tr)
iddes
Table Cell (td)
Writes data into a binary file. (Web Enabled)
Table Row (tr)
idprs
Table Cell (td)
Parameters
file
binary_data
[mimeType]
Table Row (tr)
idret
Table Cell (td)
Returns
Boolean
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
var bytes = new Array();
	for (var i=0; i<1024; i++)
		bytes[i] = i % 100;
	var f = plugins.file.convertToJSFile('bin.dat');
	if (!plugins.file.writeFile(f, bytes))
		application.output('Failed to write the file.');
	// mimeType variable can be left null, and is used for webclient only. Specify one of any valid mime types as referenced here: http://www.w3schools.com/media/media_mimeref.asp'
	var mimeType = 'application/vnd.ms-excel'
	if (!plugins.file.writeFile(f, bytes, mimeType))
		application.output('Failed to write the file.');
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idwriteTXTFile
classnode
Table Row (tr)
idname
Table Cell (td)
writeTXTFile
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
Boolean
Span
stylefloat: left; font-weight: bold;
idiets
writeTXTFile
Span
stylefloat: left;
idiets
(file, text_data, [charsetname], [mimeType])
Table Row (tr)
iddes
Table Cell (td)
Writes data into a text file. (Web Enabled)
Table Row (tr)
idprs
Table Cell (td)
Parameters
file
text_data
[charsetname]
[mimeType]
Table Row (tr)
idret
Table Cell (td)
Returns
Boolean
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
var fileNameSuggestion = 'myspecialexport.tab'
	var textData = 'load of data...'
	var success = plugins.file.writeTXTFile(fileNameSuggestion, textData);
	if (!success) application.output('Could not write file.');
	// For file-encoding parameter options (default OS encoding is used), http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html
	// mimeType variable can be left null, and is used for webclient only. Specify one of any valid mime types as referenced here: http://www.w3schools.com/media/media_mimeref.asp'
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idwriteXMLFile
classnode
Table Row (tr)
idname
Table Cell (td)
writeXMLFile
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
Boolean
Span
stylefloat: left; font-weight: bold;
idiets
writeXMLFile
Span
stylefloat: left;
idiets
(file, xml_data)
Table Row (tr)
iddes
Table Cell (td)
Writes data into an XML file. The file is saved with the encoding specified by the XML itself. (Web Enabled)
Table Row (tr)
idprs
Table Cell (td)
Parameters
file
xml_data
Table Row (tr)
idret
Table Cell (td)
Returns
Boolean
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
var fileName = 'form.xml'
var xml = controller.printXML()
var success = plugins.file.writeXMLFile(fileName, xml);
if (!success) application.output('Could not write file.');
Table Row (tr)
classlastDetailRow
Table Cell (td)