Sample solution: File access
This project shows how to use the AppendAllText, WriteAllText, and Exists static methods to interface with a flat text file through a Pega® Robotic Automation Studio version 7.1 or 8.0 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 the mscorlib.dll. To add these methods to the Robotic Automation Studio toolbox, complete the following steps:
To open the menu, right-click a blank area of the toolbox and select Choose Items.
In the Choose Toolbox Items dialog, select the Pega Robotics Static Members tab, then select the From Global Assembly Cache radio button.
Click the Assembly menu and select the mscorlib 4.0 file. Your Choose Toolbox Items dialog should resemble the following image:
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:
In the screen shown above, the methods were added to the General tab. The location of the methods depends on the tab that you specified when you selected the Add/Remove Items option. You can move toolbox items by dragging them from one tab to another.
You can download completed solutions for each version in the following table:
Published July 14, 2017 — Updated October 30, 2017