CrazyEngineers
  • Appending a file in C#

    ark

    ark

    @ark-rOPRK9
    Updated: Oct 26, 2024
    Views: 1.1K
    Hi folks ,


    I want to know how to append a file in C#,it should not delete the original content of the file . How to do it for beginning of a file , i am doing this for a log file .
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • MaRo

    MemberMar 3, 2010

    File.AppendText(filepath, text);
    Are you sure? This action cannot be undone.
    Cancel
  • ark

    MemberMar 3, 2010

    I have tried its working but its appending at the end of file but in my case i need to append to beginning of the file without altering the contents of the file .
    Are you sure? This action cannot be undone.
    Cancel
  • gaurav.bhorkar

    MemberMar 4, 2010

    ark
    I have tried its working but its appending at the end of file but in my case i need to append to beginning of the file without altering the contents of the file .
    Lets say we have two files, file1, file2.

    If you want contents of file1 to appear in beginning, then append file1 with file2.
    Else if you want contents of file2 to appear in the beginning, then append file2 with file1.

    You can always rename a file.
    Are you sure? This action cannot be undone.
    Cancel
  • MaRo

    MemberMar 4, 2010

    Add the text to a String array, reverse it, set a loop that appends the text to the file.
    Are you sure? This action cannot be undone.
    Cancel
  • ark

    MemberMar 4, 2010

    Thank you guys
    Are you sure? This action cannot be undone.
    Cancel
  • ankesh.cs2007

    MemberMar 4, 2010

    same as gaurav????
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register