This content has been archived and is no longer being maintained.

Table of Contents

Article

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.

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 the mscorlib.dll. To add these methods to the Robotic Automation 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. In the Choose Toolbox Items dialog, select the Pega Robotics Static Members tab, then select the From Global Assembly Cache radio button.
    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 image:
    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 version Built by using this build Sample solution download
7.1 7.1.26 File Access 7.1
8.0 8.0.1037 File Access 8.0

Published July 14, 2017 — Updated October 30, 2017


0% found this useful

Have a question? Get answers now.

Visit the Pega Support Community to ask questions, engage in discussions, and help others.