Skip to main content

Sample Robotic Automation solution: File access

Suggest edit Updated on September 10, 2021

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.

Automation details

Main Automation

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.

Append

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.

Write

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.

Special considerations

To create this solution, you need methods from themscorlib.dll file. To add these methods to the Robot Studio toolbox, complete the following steps:

  1. To open the menu, right-click a blank area of the toolbox and select Choose Items.
    The right-click menu in the toolbox

  2. On the Choose Toolbox Items dialog, select the Pega Robotics Static Members tab, then click From Global Assembly Cache.
    The Pega Robotics Static Members tab on the Choose Toolbox Items dialog

  3. Click the Assembly menu and select the mscorlib 4.0 file. Your Choose Toolbox Items dialog should resemble the following example:
    List of files on the Choose Toolbox Items dialog

  4. Scroll down the list to the File member and select the following methods:

    • AppendAllText (String path, String contents): Void
    • Exists
    • WriteAllText (String path, String contents): Void
  5. To add the methods, click OK. The new methods are added to the toolbox, as displayed in the following image:

    LIst of methods in the toolbox
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:

Studio versionBuilt by using this buildSample solution download
8.08.0.1037File Access 8.0
8.0.SP18.0.1037File Access 8.0 SP1
19.119.1.2.0File Access 19.1
Did you find this content helpful? YesNo

50% found this useful

Have a question? Get answers now.

Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.

Ready to crush complexity?

Experience the benefits of Pega Community when you log in.

We'd prefer it if you saw us at our best.

Pega.com is not optimized for Internet Explorer. For the optimal experience, please use:

Close Deprecation Notice
Contact us