c# streamwriter add line on file creation -


I'm successfully writing data in CSV files (yay!) In a console app Streamwriter is now excellent for me.

 using  (StreamWriter author = new streamer (file, true)) {writer.WriteLine (strToSave); }   

This code adds to an existing file or, if it does not exist, then first creates a new file.

I should do this, if the file does not exist, then create a file, write a header line for the CSV column, then type the data in general. How can I go about doing this?

Thank you.

You can check the weather first, using the file file. Example () Method If the file already exists, then you do not need to type the header, and if the current value is false , type the title (assuming that . Type Csv in the title variable header and then type the text you want.

  bool exists = file. Axis (file); (Streamer Writer is using author = new streamer (file, true)) (if (present) is the author. WrightLine; writer.WriteLine (strToSave);}    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -