Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to write CSV file in C #

Shulou Source: shulou.com Published: 2022-06-02 07:36:27 09月28日 Update

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.

Tags: Files fields clips content data text articles more knowledge articles not bad code parameters method title coding quality path path name utf-8 Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Apple NVidia vpn Docker