Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • AppendAllLines() function in .Net framework 3.5 or similar

    • 1
    • 1
    • 0
    • 1
    • 0
    • 0
    • 0
    • 982
    Answer it

    Hi !
    I was using System.IO.File.AppendAllLines() function in .Net Framework 4.0 but due to some reason I have to migrate my project into .Net Framework 3.5. But in .Net Framework 3.5 I am not able to use this function.

    Following is the code to give an idea what I was doing in .Net Framework 4.0:-

    string[] name = new string[] { "Mayank Srivastava","Rahul Bhandari","Ankit Bisht"};
    System.IO.File.AppendAllLines(filepath, name);
    

    Anybody have any idea..? Thanks in advance..!

 1 Answer(s)

  • Hi Mayank,

    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);
    }
    
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: