Skip to main content

Introduction to WriteFile and ReadFile Tasks

Writing content to a file

R
Written by Riku Virtanen
Updated over a year ago

WriteFile & ReadFile

The WriteFile Task will write the given content to a file in the SFTP server. The Task can either create a new file, overwrite an existing one or append to it. The Task will take path and content attributes which it will use to find a specific file or to create a new one. You are able to specify the encoding of the file name given as a parameter.

Let's go through the input parameters of the Task one by one. The first parameter is Path. This expects the full absolute path to the location where the file is ordered to write. The Path parameter also needs the filename. The Content parameter needs the content of the file. The content needs to be in string format.

The next parameter, File encoding, enables you to choose which encoding is used with both the filename and the content to be written. Possible values are: UTF-8, ANSI, ASCII, WINDOWS1252 and Unicode. You can also select Other which will enable you to write the encoding code page name.

Next you can choose what is done if a file with the same name already exists in the destination. You can choose either Error which will make the Task throw an exception, Append which will append the content to the file or Overwrite which will delete the existing file and create a new one with the same name. When choosing Append you can also choose if a new line is added to the start of the content before appending it to the existing file.

The WriteFile Task returns a Result object which includes the path where the file was written and the size of the file in megabytes.

ReadFile

The ReadFile Task reads a file from the SFTP server and returns a Result object which has the content in string format. The Task only takes the path of the file as a parameter addition to the encoding of that file name. The path parameter expects a full path to the file including the name of the file. Like in the WriteFile Task the file name encoding can be set with the code page name by selecting Other from the selector.

The ReadFile Task returns a Result object which includes the file content, full path, size in megabytes and last write time in local time.

Did this answer your question?