How to append data to file and clear it when it's closed

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • y khan
    New Member
    • May 2011
    • 2

    How to append data to file and clear it when it's closed

    I have values changing at some rate per second that i am storing in a variable then i am printing these values in a file. So i have to append the values into the file so that they are not over written and all the values are displayed line by line. But when i close the program i need the file to be cleared. But only when i close the program and not when the function exits that it clears the file.
  • samueal
    New Member
    • Apr 2011
    • 8

    #2
    To append the data to a file use:

    Code:
    File.AppendAllText("myfile.txt","I am a C# developer");
    use \r\n to write in the new Line.

    To clear the file while closing write the Code in the form's Dispose method

    Comment

    Working...