string path = Path.Combine(outputpath, outputfile); fileStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write); writer = new StreamWriter(fileStream, Encoding.UTF8); for (i = 0; i < dt.Columns.Count - 1; i++) { writer.Write(dt.Columns[i].ColumnName + ;); } writer.Write(dt.Columns[i].ColumnName + ;); writer.WriteLine(); /*For Data in the Rows*/ foreach (DataRow row in dt.Rows) { object[] array = row.ItemArray; for (i = 0; i < array.Length - 1; i++) { writer.Write(array[i].ToString() + ;); } writer.Write(array[i].ToString()); writer.WriteLine(); } writer.WriteLine("-------------------------------------------"); writer.Flush(); writer.Close();
// This text is always added, making the file longer over time using (StreamWriter sw = File.AppendText(path)) { sw.WriteLine("This"); sw.WriteLine("is Extra"); sw.WriteLine("Text"); }
System.IO.StreamWriter file = new System.IO.StreamWriter("YourFile", true);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)