Share this page

# lr.read_file

Reads a file into a parameter.

## C#

int lr.read_file( string <filename>, string <output parameter name>, int <continue on error>);

String and Parameter Functions

## Arguments

Name | Comments
--- | ---
filename | The full pathname or the pathname relative to the script folder.
output parameter name | The name of the parameter that stores the file contents.
continue on error | lr.EXIT_VUSER (0) or lr.EXIT_ACTION_AND_CONTINUE (1)

lr.read_file reads a file and saves the file contents in a parameter.

## Return Values

This function returns the number of bytes read. On failure, returns a negative number.

## Parameterization

Parameterization is not applicable to this function.

## Example

These actions show the usages of lr.read_file.

    public int action() throws Throwable {

        lr.read_file("test.txt","testparam", lr.EXIT_ACTION_AND_CONTINUE);
        lr.log_message(lr.eval_string("{testparam}"));
        // If file read, outputs file content. If not found or not read, outputs: {testparam}

        //not found with error
        lr.read_file("notfound.txt","notfound", lr.EXIT_VUSER);
        /* Log output:
           Error: can not open file
           Abort was called from an action.
           Ending Vuser...
        */

        return 0;
    }//end of action

Tips to improve your search results... VuGen Function Reference Version 26.1 Function Reference 26.1 All View Local Help Center View Online Help Center Version: