This project shows how to use the AppendAllText, WriteAllText, and Exists static methods to interface with a flat text file through a Pega Robot Studio solution.
The solution prompts the user for a file name. If an existing text file is entered, text is appended to the text in the file. If a new file name is entered, the file is created and text is added to the file.
This automation checks to see if the file name entered in the text box on the Windows form exists. If the file exists, a message indicates that the file was found and then the Append automation is launched. The contents of the text box from the Windows form (the file name including path) is passed to the Append automation.
If the file is not found, a message displays indicating that the file was not found and the Write automation is launched. The contents of the text box from the Windows form (the file name and path) is passed to the Write automation.
This automation calls the AppendAllText method by using the file name that is provided by the user on the Windows form. The method opens the file and appends the following text: “I’m appending”. The file is then closed and saved.
This automation calls the WriteAllText method by using the file name that is provided by the user on the Windows form. The method creates the file and enters the text: “Openspan Rocks!” The file is then closed and saved.
To create this solution, you need methods from themscorlib.dll file. To add these methods to the Robot Studio toolbox, complete the following steps:
To open the menu, right-click a blank area of the toolbox and select Choose Items.
On the Choose Toolbox Items dialog, select the Pega Robotics Static Members tab, then click From Global Assembly Cache.
Click the Assembly menu and select the mscorlib 4.0 file. Your Choose Toolbox Items dialog should resemble the following example:
Scroll down the list to the File member and select the following methods:
- AppendAllText (String path, String contents): Void
- WriteAllText (String path, String contents): Void
To add the methods, click. The new methods are added to the toolbox, as displayed in the following image:
You can download completed solutions for each version in the following table:
|Studio version||Built by using this build||Sample solution download|
|8.0||8.0.1037||File Access 8.0|
|8.0.SP1||8.0.1037||File Access 8.0 SP1|
|19.1||22.214.171.124||File Access 19.1|