title: How can I utilize StreamWriter to write to a csv file?
body: <p>So here's what I'm working with.  I'm trying to take an XML file, pull the info from the attributes, append them together, and write it to a CSV file.  I'm still relatively new to programming, and the other programmer is out of the office today, so I could really use some assistance.</p>
  
  <p>My first question, regards the StringBuilder.  Do I need to have an AppendLine at the end of my StringBuilder, so that each string output from the foreach loop is on a new line?  And would I need to do that inside the foreach loop?</p>
  
  <p>My second question regards actually writing my string to the CSV file.  Would it look something like? </p>
  
  <pre><code>swOutputFile.WriteLine(strAppendedJobData)
  </code></pre>
  
  <p>And I think this would also go inside the foreach loop, but I'm not too sure.</p>
  
  <p>Thanks for the help, I hope I've worded my question in a somewhat easy to understand manner.</p>
  
  <pre><code>//Create a stream writer to write the data from returned XML job ticket to a new CSV
          StreamWriter swOutputFile;
          string strComma = ",";
          swOutputFile = new StreamWriter(new FileStream("C:\\Dev\\AppendedJobData.csv", FileMode.Create, FileAccess.Write, FileShare.Read));
  
          //Get nodes from returned XML ticket
          XmlNodeList xmlJobs = xdResults.SelectNodes("/Updates/Jobs/Job");
          //Pull out data from XML attributes
          foreach (XmlElement xeJobUpdate in xmlJobs)
          {
              //Break down the job data
              string strProjectID = xeJobUpdate.GetAttribute("SharpOwlProjectID");
              string strJobNumber = xeJobUpdate.GetAttribute("JobNumber");
              string strClientCode = xeJobUpdate.GetAttribute("SharpOwlClientCode");
              string strClient = xeJobUpdate.GetAttribute("Client");
              string strVCAOffice = xeJobUpdate.GetAttribute("VCAOffice");
              string strLoadStatus = xeJobUpdate.GetAttribute("LoadStatus");
  
              //Build the string to be added to the new CSV file
  
              StringBuilder sbConcatJob = new StringBuilder();
              sbConcatJob.Append(strProjectID).Append(strComma).Append(strJobNumber)
                  .Append(strComma).Append(strClientCode).Append(strComma).Append(strClient).Append(strComma)
                  .Append(strVCAOffice).Append(strComma).Append(strLoadStatus).Append(strComma);
              string strAppendedJobData = sbConcatJob.ToString();
  </code></pre>