ng:fileExist

ng:fileExist

The ng:fileExist Xpath function has this format:

ng:fileExist(path)
where path contains the path to a file, that should be verified.

 

The function returns true, if the file exists and false, if the file does not exist.

The function can e.g. be used for verifying, if a file exists before you try to embed it in a PDF file.


The function can also be used for verifying if a folder exists. This expression e.g. validates to true, if the folder 'Windows' is found on the C-drive: ng:fileExist('C:\Windows')

Notes
The ng:fileExist() function returns the value true() if the input parameter is an invalid expression or null, so it is highly recommended to test that your setup works correctly both if the file does exist and also if the file does not exist.

 

Examples

On the Windows platform you can use this expression:

ng:fileExist('C:\temp\testfile.txt')

On the IBM i you can e.g. use this to verify if an image is found in the IFS with this expression:

ng:fileExist('/IFormNG2/MyImages/CHKPRE.png')
ng:fileExist('//QNTC/MyServer/Share/filename.pdf')


Please notice, that the reference to the file is not a URL, so you should not e.g. replace any spaces in the path and file name with %20.
This is a valid test to verify if the file 'My text file.txt' exists:

ng:fileExist('C:\temp\My text file.txt')


This expression is always true no matter if the file exists or not:
The reason is, that the input parameter for the ng:fileExist function is invalid (that is indicated with the red text, 'Expression' and the error message/warning below the expression.
So although an invalid expression has been setup, the if condition is considered true (To correct the expression you need to add single or double quotes around the fixed text).


Related function is ng:resourceExist.

    • Related Articles

    • ng:resourceExist

      This function checks, if a resource in InterFormNG2 exists or not. The function returns a boolean: true or false. The ng:resourceExist Xpath function has this format: ng:resourceExist(resource,path) where: resource Resource is the type of resource in ...
    • ng:decrypt

      The built-in function, ng:decrypt is linked with the encryption functions: ng:encrypt and the workflow component, Set secure workflow variable. The function, ng:decrypt() can decrypt contents, that was previously encrypted with these functions. The ...
    • ng:minimum

      InterFormNG2 includes the special built-in XPath function, ng:minimum. This function returns the smallest value of two numeric arguments. The function only accepts two numeric arguments - no more and no less. Examples: ng:minimum(-14,2) returns: -14 ...
    • ng:spaceConcat

      The built-in function, ng:spaceConcat(), helps concatenate two strings with a space character automatically inserted between them. Here is an example: This XPath expression: ng:spaceConcat('First name:', 'Jon') outputs this string: First name: Jon ...
    • ng:base64

      The built-in function, ng:base64() converts a string (text) into a base64 based string. This can e.g. be used, if you want to insert any kind of data into an XML node, without substituting any characters, that are not allowed. This function is ...