How could I add 2 header records that are to appear BEFORE the detail records built via an array in C#?

I am writing a C# console application with Visual Studio 2005.
How could I add 2 header records that are to appear BEFORE the detail records built via an array that starts with the line:
COMMENT: CHECK NUMBER #1
---------------------------------------
The 2 header records are as follows:
1) BANK CHECKS
2) FOR MANUFACTURERS HANOVER TRUST CO.

----------------------------------
My C# code is as follows:
----------------------------------
using System;
using System.Xml;
using System.IO;
using System.Text.RegularExpressions;
namespace ReadXml1

{

    class Class1
    {
        static void Main(string[] args)
        {
           
            string goodFilePath = @"U:\Harris\Ha.ard.ind";
            string emptyFilePath = @"U:\Harris\Ha.ard";
            string tiffFilePath = @"U:\Harris\Ha.ard.out";

            if (File.Exists(goodFilePath))
            {
                File.Delete(goodFilePath);
            }

            if (File.Exists(emptyFilePath))
            {
                File.Delete(emptyFilePath);
            }

            if (File.Exists(tiffFilePath))
            {
                File.Delete(tiffFilePath);
            }    

            DirectoryInfo parentDirectory = new DirectoryInfo(@"U:\Hn");                
         
            foreach (FileInfo file in parentDirectory.GetFiles())
            {
                StreamWriter sw = null;
                try
                {
                    if (XmlFile(file.FullName))
                    {
                        sw = new StreamWriter(goodFilePath);
                        ProcessFile(file.FullName, sw);
                    }
                    else
                    {              
                        sw = new StreamWriter(emptyFilePath);                            
                        File.Copy(file.FullName, @"U:\Harris\Ha.ard.out");                        
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    if (sw != null) sw.Close();
                }
            }
            Console.WriteLine("Processing done. Press enter to exit ... ");
            Console.ReadLine();
        }

        private static void ProcessFile(string filePath, StreamWriter sw)
        {
            int i = 0;
            string[,] arr1 = new string[2000, 19];
            int iCheckNumber = 0;
            XmlTextReader reader = null;
            try
            {
                reader = new XmlTextReader(filePath);
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        if (reader.Name == "csc:check_number")
                        {
                            iCheckNumber = iCheckNumber + 1;
                            arr1[i, 0] = "COMMENT: CHECK NUMBER #" + iCheckNumber;
                            arr1[i, 1] = "GROUP_FIELD_NAME:CheckNumber";
                            String e = reader.ReadElementContentAsString();
                            String formattedString = e.Substring(6, 3);
                            String formattedString1 = e.Substring(9, 6);
                            arr1[i, 2] = "GROUP_FIELD_VALUE:" + formattedString1;
                            arr1[i, 16] = "GROUP_FIELD_VALUE:" + formattedString;
                        }
                       
                    }
                }

                for (int iter = 0; iter < i; iter++)
                {
                    for (int j = 0; j < 19; j++)
                    {
                        sw.WriteLine(arr1[iter, j]);
                    }
                }
            }
            finally
            {
                reader.Close();
            }
        }
        static bool XmlFile(string filePath)
        {
            string line;
            bool xmlFile = false;
            StreamReader sr = null;
            //Regex regExpr = null;
            try
            {
                sr = new StreamReader(filePath);
                line = sr.ReadLine();
                if (line.Equals("<?xml version=\"1.0\"?>"))
                    xmlFile = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                xmlFile = false;
            }
            finally
            {
                if (sr != null) sr.Close();
            }
            return xmlFile;
        }
    }
}
zimmer9Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jjardineCommented:
If I understand correctly, can you modify your loop to look like this?  

             for (int iter = 0; iter < i; iter++)
                {
                    for (int j = 0; j < 19; j++)
                    {
if j = 0 then
  sw.WriteLine ("Header 1")
  sw.WriteLine ("Header 2")
end if
                        sw.WriteLine(arr1[iter, j]);
                    }
                }
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
anarki_jimbelSenior DeveloperCommented:
Or may be simply (I didn't try...):


 sw.WriteLine("Header 1");
 sw.WriteLine("Header 2");
 for (int iter = 0; iter < i; iter++)
                {
                    for (int j = 0; j < 19; j++)
                    {
                        sw.WriteLine(arr1[iter, j]);
                    }
                }
0
anarki_jimbelSenior DeveloperCommented:
Really, I prefer to use lists, not arrays. In your case you may use a list of lists.

The main benefit is that you may easily change the size of your lists, insert elements at the beginning or in any other position, remove elements etc.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.