'Adding headers and footers using SSIS script task

I have looked through all posts on headers and footers and I only see partial scrips. I am no fundi on C@ or script task. Below is my code but it is failing. My final output will be a pipe delimiter with a header and footer.

''''' // C# Code #region Namespaces using System; using System.Data; using System.IO; // Added using Microsoft.SqlServer.Dts.Runtime; using System.Windows.Forms; #endregion

namespace ST_719acd579f7e46adb5d68fb2fdd19625
{
    [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
    public partial class ScriptMain : 
Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
    {

        public void Main()
        {
            object p = base.PreExecute();
            tw = new StreamWriter(Variables.User::HeaderAddress);
            tw.WriteLine("HEADER");
        }

        public override void Input0_ProcessInputRow(Input0Buffer Row)
        {
        tw.WriteLine(Row.WhateverFieldsYouNeed);
        }

        public override void PostExecute()
        {
            base.PostExecute();
            tw.WriteLine("User::FooterAddress");
            tw.Close();
        }

        // Close Script Task with success
         Dts.TaskResult = (int)ScriptResults.Success;
        }

        #region ScriptResults declaration
        /// <summary>
       /// This enum provides a convenient shorthand within the scope of this class for 
    setting the
       /// result of the script.
       /// 
       /// This code was generated automatically.
       /// </summary>
       enum ScriptResults
       {
            Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
            Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
       };
        #endregion
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source