title: c# save my datatable into a [txt] file
body: <p>I research all related title/topics to this problem but none of it seems to solve my problem.. it produces the 'Seperated_File.txt' but it is totally a blank text file. Thanks for your reply.</p>
  
  <p>UPDATED (THE SOLUTION)</p>
  
  <pre><code>        string[] lines = File.ReadAllLines(@"d:\Processed_Text.txt");
          DataTable dt = new DataTable();
  
          dt.Columns.Add("IP Address");
          dt.Columns.Add("Date");
          dt.Columns.Add("Time");
          dt.Columns.Add("GMT");
          dt.Columns.Add("Method");
          dt.Columns.Add("Resource");
          dt.Columns.Add("Port");
          dt.Columns.Add("Bytes");
          dt.Columns.Add("Services");
          dt.Columns.Add("Destination");
          dt.Columns.Add("Operating System");
  
          foreach (string line in lines)
          {  
              string[] split = line.Split(' ', ':');
  
  
              split = split.Where(r =&gt; !string.IsNullOrWhiteSpace(r)).ToArray();
  
              Foo foo = new Foo();
  
              foo.IPAddress = split[0];
              foo.Date = split[1];
              foo.Time = string.Format("{0}:{1}:{2}", split[2], split[3], split[4]);
              foo.GMT = split[5];
              foo.Method = split[6];
              foo.Resource = split[7];
              foo.Port = split[8];
              foo.Bytes = split[9];
              foo.Service = split[10];
              foo.Destination = split[11];
              foo.OS = split[12];
  
              dt.Rows.Add(foo.IPAddress, foo.Date, foo.Time, foo.GMT, foo.Method, foo.Resource, foo.Port, foo.Bytes, foo.Service, foo.Destination, foo.OS);
          }
  
            using (StreamWriter sw = new StreamWriter(@"d:\Seperated_Text.txt"))
            foreach (DataRow dr in dt.Rows)
           {
              Console.WriteLine(string.Format("{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10}", dr[0], dr[1], dr[2], dr[3], dr[4], dr[5], dr[6], dr[7], dr[8], dr[9], dr[10]));
              sw.WriteLine(String.Join(",", dr.ItemArray));
              sw.WriteLine(dr);
  
          }
          Console.ReadLine();
      }
  </code></pre>