How to Develop a Robotic Process Automation (RPA) in C# Language

What is Robotic Process Automation (RPA)?

 
It is a technology that's based on a business process automation that works with tasks to execute alongside software. Below, I will explain an example of Console Application in C# language that can be executed by a user.
 
How To Developer A Robotic Process Automation (RPA) In C# Language
 
Let's read below my friends!!!
 

How to develop a Robotic Process Automation in C# language?

 
The main objective in this robot example is to check the domains "@domain.com.br" in a .txt file belonging to the company, and the output in other txt files where all the emails are. Also, the robot example will ignore the domains that don't belong to the company.
 
Input
 
How To Developer A Robotic Process Automation (RPA) In C# Language
 
Output
 
How To Developer A Robotic Process Automation (RPA) In C# Language
 
Let's learn with the code below:
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.IO;  
  4. using System.Linq;  
  5. using System.Text;  
  6. using System.Threading.Tasks;  
  7.   
  8. namespace ConsoleApp_ReadData  
  9. {  
  10.     class Program  
  11.     {  
  12.         static void Main(string[] args)  
  13.         {  
  14.             try  
  15.             {  
  16.                 string[] lines = File.ReadAllLines(@"C:\Users\NameUser\Documents\Input\emails.txt");  
  17.   
  18.                 int countLines = 0;  
  19.                   
  20.                 using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\NameUser\Documents\Output\Result.txt"))  
  21.                 {  
  22.                     foreach (var item in lines)  
  23.                     {  
  24.                         if (item.Contains("@company.com.br"))  
  25.                         {  
  26.                             System.Console.WriteLine(" ");  
  27.                             System.Console.WriteLine(" --- Are company --- ");  
  28.                             System.Console.WriteLine(item);  
  29.   
  30.                             if (item != "")  
  31.                                 file.WriteLine(item);  
  32.                         }  
  33.                         else if (!item.Contains("@company.com.br"))  
  34.                         {  
  35.                             System.Console.WriteLine(" ");  
  36.                             System.Console.WriteLine(" --- Not Are company --- ");  
  37.                             System.Console.WriteLine(item);  
  38.                         }  
  39.                         countLines++;  
  40.                     }  
  41.                 }  
  42.                 Console.WriteLine("Count: {0}", countLines);  
  43.                 Console.ReadLine();  
  44.             }  
  45.             catch (FileNotFoundException e)  
  46.             {  
  47.                 Console.WriteLine("[File not found!] {0}", e);  
  48.                 Console.ReadLine();  
  49.             }  
  50.               
  51.         }  
  52.     }  
  53. }  
Line 16: Specify the directory you will use to read the txt file.
Line 18: A count to check the number of data.
Line 20: The directory will create and write the txt file output data.
Line 22: Looping inside the txt file.
Line 24: Verify if the email contains the name "@company.com.br" and will display it to the user.
Line 30: Will write the valid domain contain the name "@company.com.br" on the output txt file.
Line 33: Will check too the domain don't contain the name "@company.com.br" and will display to the user.
Line 39: Display to the user the sum total that the txt file has.
Line 47: Display an exception to the user if the directory doesn't exist.
 
It should show the image below if you execute the Console Application
 
How To Developer A Robotic Process Automation (RPA) In C# Language
 
I hope this helped you to understand the world of RPA!
 
Thank's for reading it. I will see you in the next article.
 
 Good vibes to you!!! 


Similar Articles