AppendAllLines is work in .net framework 4.5
but how can we use append all line in 3.5
//4.5
string[] a = new string[] { fa + " "+ lastModified };
System.IO.File.AppendAllLines(filepath, a);
//3.5
string[] a = new string[] { fa + " "+ lastModified };
var ab = string.Join(Environment.NewLine, DataList.Select(x => x.blah blah blah).ToArray());
string outputFilePath = @"C:\output.txt";
File.AppendAllText(outputFilePath, ab);
public static void AppendAllLines(string path, IEnumerable<string> lines)
{
using (var writer = new StreamWriter(path, true))
foreach (var line in lines)
writer.WriteLine(line);
}
How can we use AppendAllLines in .net framework 3.5
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

sachin Joshi6 pointsPosted May 26, 2015, 5:25 AM EDT
You can't use File.AppendAllLines() function in version prior to .NET 4.0. It only works in version 4.0 & above.
Instead what you can do is create a custom AppendAllLines() function easily to solve your problem. In the following sample code we are iterating through each line and appending them one by one to the file specified using "filePath" variable.
Example:
//Function definition public static void AppendAllLines(string filePath, IEnumerable<string> inputLines) { using (var writer = new StreamWriter(filePath, true)) foreach (var line in inputLines) writer.WriteLine(line); }Manoj BhoirRank #599 · 4K pointsPosted May 26, 2015, 7:51 AM EDT
public static void AppendAllLines(string path, IEnumerable<string> lines) { using (var writer = new StreamWriter(path, true)) foreach (var line in lines) writer.WriteLine(line); }How to Use :string[] a = new string[] { fa + " "+ lastModified }; // Your array of String with new lines to add into file. AppendAllLines(filepath, a);