Posted By

hoffstein on 10/05/10


Tagged

csv


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Tyster


Simple CSV Writer


 / Published in: C#
 

  1. using System;
  2. using System.IO;
  3. using System.Text;
  4.  
  5. namespace RedHook.Utils
  6. {
  7. public class CsvWriter
  8. {
  9. public static void Write(string[][] data, string outputPath)
  10. {
  11. if (data == null) throw new ArgumentException("Parameter \"data\" cannot be null");
  12. if (outputPath == null) throw new ArgumentException("Parameter \"outputPath\" cannot be null");
  13.  
  14. StringBuilder sb = new StringBuilder();
  15. for (int i = 0; i < data.GetLength(0); i++)
  16. {
  17. if (data[i] == null) continue;
  18. sb.AppendLine(string.Join(",", data[i]));
  19. }
  20. File.WriteAllText(outputPath, sb.ToString());
  21. }
  22. }
  23. }

Report this snippet  

You need to login to post a comment.