Click here to Skip to main content
15,918,742 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
See more:
AppendAllLines is work in .net framework 4.5
but how can we use append all line in 3.5
C#
//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);
}
Posted
Updated 18-May-15 20:19pm
v2
Comments
Tomas Takac 19-May-15 2:21am    
Apparently you have code for 3.5 already. So what's the problem?
Afzaal Ahmad Zeeshan 5-Jun-15 10:12am    
Good catch!

You can't use File.AppendAllLines in version prior to .NET 4.0 - it was added at that point.

Instead, you would need to do something like the string.Join code you show in your question.
 
Share this answer
 
C#
string[] a = new string[] { fa + " "+ lastModified };
                          using (TextWriter writer = File.AppendText(filepath))
                          {
                              foreach (string actor in a)
                              {
                                  writer.WriteLine(actor);
                              }
                          } Console.WriteLine(fa);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900