Creating a FileWriter activity
CodeActivity
is an abstract class inherited from Activity
. We can put our logic code in its Execute
method. In this task, we are going to create an activity that will write data to a text file.
How to do it...
Create the FileWriter activity:
Add a new code file to
ActivityLibrary
project namedFileWriter.cs
. Then replace all default code with the following code:using System; using System.Activities; using System.Threading; public sealed class FileWriter : CodeActivity { [RequiredArgument] public InArgument<string> fileName { get; set; } [RequiredArgument] public InArgument<string> fileData { get; set; } protected override void Execute(CodeActivityContext context) { string lines = fileData.Get(context); // Write the string to a file. System.IO.StreamWriter file = new System.IO.StreamWriter(fileName.Get(context)); file.WriteLine(lines); //simulate writing process. ...