How to write CSV file in C #
This article will explain in detail how to write CSV files in C#. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
The code that C# writes to the text file:
/ / Open or create a new text file. _ indFileName is the file path name using (FileStream fs = new System.IO.FileStream (_ indFileName, FileMode.OpenOrCreate, FileAccess.Write)) {/ / the following two sentences are emptying the file contents fs.Seek (0, SeekOrigin.Begin); fs.SetLength (0) / / start writing to the file. The second parameter of streamwriter is to set the encoding. The default is utf-8 using (StreamWriter m_streamWriter = new StreamWriter (fs)) {/ / write the file title, and write the data m_streamWriter.WriteLine (field 1 + "," + field 2 + "," + field 3 + "," + field 4) in a circular manner. " / / disable writing data, complete data writing m_streamWriter.Flush (); m_streamWriter.Close ();} fs.Close ();} share here on how to write CSV files in C#. I hope the above content can be helpful to everyone and learn more knowledge. If you think the article is good, you can share it for more people to see.