title: C# Plugin- Break up array on every second ","
body: <p>I have made a FetchXML query that returns data from my CRM2013 grid
  The data is passed into a list
  Which is then turned into a CSV file with the following code;</p>
  
  <pre><code>EntityCollection result = service.RetrieveMultiple(new FetchExpression(fetchxml)); foreach (var c in result.Entities)
                  {
                      if (result != null &amp;&amp; result.Entities.Count &gt; 0)
                      {
                          List&lt;string&gt; _product = new List&lt;string&gt;();
                          foreach (Entity _entity in result.Entities)
                          {
                             _product.Add(((EntityReference)c.Attributes["productid"]).Name.ToString());
  
                             _product.Add(_entity.Attributes["quantity"].ToString());  
  
                          }
  
                          CSVFile = string.Join(",", _product.ToArray());
  
  
  
                          string AddressPath = "FM-OR" + "_";
                          string AddressSavePath = @"\\fm\CRMdata\maesteg\" + AddressPath + ".csv";
                          System.IO.File.WriteAllText(AddressSavePath, CSVFile.ToString());
  </code></pre>
  
  <p>The output would be as follows</p>
  
  <p>ProductExample1, 1.0, ProductExample2, 4.0, ProductExample3, 2.0</p>
  
  <p>What I want is the output to now be</p>
  
  <p>ProductExample1, 1.0</p>
  
  <p>ProductExample2, 4.0</p>
  
  <p>ProductExample3, 2.0</p>
  
  <p>Any suggestions at how I would achieve this?</p>
  
  <p>Thanks</p>
  
  <p><strong>Update</strong></p>
  
  <p>Didn't feel like I quite explained it properly
  With the output I want, I want them to be separate strings so that I can output a different CSV file for each Product + Quantity in the list
  Thanks</p>
  
  <p><strong>Update</strong></p>
  
  <p>Code with new suggestions implemented, error is described in comment below</p>
  
  <pre><code>EntityCollection result = service.RetrieveMultiple(new FetchExpression(fetchxml)); foreach (var c in result.Entities)
              {
                  if (result != null &amp;&amp; result.Entities.Count &gt; 0)
                  {
                      List&lt;string&gt; _product = new List&lt;string&gt;();
                      foreach (Entity _entity in result.Entities)
                      {
                          string productid = (((EntityReference)_entity.Attributes["productid"]).Name.ToString());
  
                          string quantity = _entity.Attributes["quantity"].ToString();
  
                          CSVFile = productid + "," + quantity;
  
                          int n =1;
                          string AddressPath = "FM-OR" + "_" +actualID + "_" + n;
                          string AddressSavePath = @"\\fm\CRMdata\maesteg\" + AddressPath + ".csv";
                          System.IO.File.WriteAllText(AddressSavePath, CSVFile.ToString());
                          n++;
  
                      }                                        
  
                  }
  
              }
  </code></pre>
  
  <p>Thanks</p>