Adding text to a tab delimited file with a foreach

I am creating a tab delimited file and I am trying to use a foreach loop to write data in a row - I was wondering if anyone knew how to do that?
if (sfdToPC.ShowDialog() == DialogResult.OK)
            {
                myPath = Path.GetFileName(sfdToPC.FileName);
                FileStream fs = new FileStream(myPath, FileMode.Create, FileAccess.ReadWrite);
                StreamWriter outputFile = new StreamWriter(fs);
                string thedate = jobSummary[0].CreatedOn.ToString("dd MMM yyyy ");
                string theTime = jobSummary[0].CreatedOn.ToString("hh:mm:ss");
                string thefile = "Surefire Accepted Survey Data as Text" + "\r\n\r\n" +
                                 "Job File Name = " + wellname + ".itj" + "\r\n" +
                                 "Job Notes: " + jobSummary[0].JobNotes.ToString() + "\r\n" +
                                 rig + "\r\n" +
                                 rig + " " + rignumber + "\r\n" +
                                 "PV" + "\r\n" +
                                 "Created On = " + thedate + " @ " + theTime + "\r\n" +
                                 totalSurveys + " Total Surveys in File. " + totalAcceptedSurveys + " are tagged as Accepted" + "\r\n" +
                                 "\r\n" +
                                 "The Vertical Depth and Maximum Departure values below were calculated using the Minimum Curvature Model." + "\r\n" +
                                 "This information is intended for reference purposes ONLY." + "\r\n" +
                                 "It is NOT intended to replace professional oversight or sound judgement." + "\r\n" +
                                 "For more detail on the data and algorithms used to compute this information, contact your sales agent." + "\r\n" +
                                 "\r\n\r\n" +
                                 "SURVEY DEPTH" + "\t" + "VERTICAL DEPTH" + "\t" + "MAXIMUM DEPARTURE" + "\t" + "TGF" + "\t" + "BATTERY" + "\t" + "TEMPERATURE" + "\t" + "SURVEY #" + "\t" + "SURVEY TYPE" + "\t" + "SURVEY DATE AND TIME" + "\t" + "BIT DEPTH" + "BIT TRIP NUMBER" + "\t" + "BIT TO TOOL OFFSET" + "\r\n";
                                 foreach(var list in MyAcceptedSurveyList)
                                 {
                                     list.SurveyDepth.ToString() += "\t" + list.SurveyAngle.ToString() += "\t";  

                                 }

Open in new window

LVL 6
r3nderAsked:
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.

AndyAinscowFreelance programmer / ConsultantCommented:
So, what is your problem?
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
r3nderAuthor Commented:
ok I added a string builder  but I need to add that data that is in the for loop to the existing file
if (sfdToPC.ShowDialog() == DialogResult.OK)
            {
                StringBuilder sb = new StringBuilder();
                myPath = Path.GetFileName(sfdToPC.FileName);
                FileStream fs = new FileStream(myPath, FileMode.Create, FileAccess.ReadWrite);
                StreamWriter outputFile = new StreamWriter(fs);
                string thedate = jobSummary[0].CreatedOn.ToString("dd MMM yyyy ");
                string theTime = jobSummary[0].CreatedOn.ToString("hh:mm:ss");
                string thefile = "Surefire Accepted Survey Data as Text" + "\r\n\r\n" +
                                 "Job File Name = " + wellname + ".itj" + "\r\n" +
                                 "Job Notes: " + jobSummary[0].JobNotes.ToString() + "\r\n" +
                                 rig + "\r\n" +
                                 rig + " " + rignumber + "\r\n" +
                                 "PV" + "\r\n" +
                                 "Created On = " + thedate + " @ " + theTime + "\r\n" +
                                 totalSurveys + " Total Surveys in File. " + totalAcceptedSurveys + " are tagged as Accepted" + "\r\n" +
                                 "\r\n" +
                                 "The Vertical Depth and Maximum Departure values below were calculated using the Minimum Curvature Model." + "\r\n" +
                                 "This information is intended for reference purposes ONLY." + "\r\n" +
                                 "It is NOT intended to replace professional oversight or sound judgement." + "\r\n" +
                                 "For more detail on the data and algorithms used to compute this information, contact your sales agent." + "\r\n" +
                                 "\r\n\r\n" +
                                 "SURVEY DEPTH" + "\t" + "VERTICAL DEPTH" + "\t" + "MAXIMUM DEPARTURE" + "\t" + "TGF" + "\t" + "BATTERY" + "\t" + "TEMPERATURE" + "\t" + "SURVEY #" + "\t" + "SURVEY TYPE" + "\t" + "SURVEY DATE AND TIME" + "\t" + "BIT DEPTH" + "BIT TRIP NUMBER" + "\t" + "BIT TO TOOL OFFSET" + "\r\n";
                outputFile.WriteLine(thefile);
                outputFile.Close();
                foreach (var list in MyAcceptedSurveyList)
                {
                    sb.Append(list.SurveyDepth.ToString() + "\t" + list.SurveyAngle.ToString() + "\t" + "\r\n");

                }

                using (StreamWriter outfile = new StreamWriter(myPath))
                {
                    outfile.WriteLine(sb.ToString());
                }

                //outputFile.WriteLine(thefile);
                outputFile.Close();

Open in new window

0
r3nderAuthor Commented:
found out how to  do it added true to the new streamwriter so it appended to the file thanks Andy
 foreach (var list in MyAcceptedSurveyList)
                {
                    sb.Append(list.SurveyDepth.ToString() + "\t" + list.SurveyAngle.ToString() + "\t" + "\r\n");

                }

                using (StreamWriter outfile = new StreamWriter(myPath,true))
                {
                    outfile.WriteLine(sb.ToString());
                }

Open in new window

0
r3nderAuthor Commented:
Thank for telling me I was on the right path
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.