WriteFile Overview

WriteFile service writes the specified text data into the specified file. If the file does not exist, it will be created. If file already exists, it will be overwritten. We usually use WriteFile service to create .txt and .csv file. For .pdf file, please refer to HtmlStringToPDFStream service.

WriteFile Use Example

Basic WriteFile Use

This is an example that we write a file specified text data. We first checked if the directory exists. If not, we will create a new directory before we write the file.

In EASYProcess, the service returns Written = True, which means it is created successfully.

In the target directory, you can see the file created with the data we wrote.

If the directory doesn’t exist and we don’t check it before using WriteFile service, EASYProcess will throw the following exception.

Use WriteFile to override existing file

In the previous example, we have created a file TextAttach.txt in the test directory. In this example, we call the service again with the same directory and file name.

There is only one file in that directory with the new text message after the service runs successfully.