How to Write to a CSV File on VB.NET

Written by jim campbell
  • Share
  • Tweet
  • Share
  • Email

Comma delimited files (CSV) allow administrators to transfer data between different platforms. You can write to a CSV file using VB.NET so that you can export data to import to another database application. CSV files contain the plain text format, so you can write to a text file and name it with a CSV extension in VB.NET.

Skill level:

Other People Are Reading


  1. 1

    Click the Windows "Start" button and select "All Programs." Click ".NET Framework" and then click the "Visual Studio" shortcut to open the software.

  2. 2

    Double-click the VB.NET project file to open the project in the development software. In "Solution Explorer," right-click the file you want to edit and select "View Code."

  3. 3

    Create the variable for the CSV file. Type the following code in the editor:

    Dim file As String = "C:\myfolder\Test.csv"

    Replace the string content with the location and name of the CSV file you want to create.

  4. 4

    Link the new file variable to the "output" stream. The output stream variable prepares the file so that you can write to it from your program. Type the following code:

    Dim out As IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(file, False)

  5. 5

    Write data to the CSV file. The following code shows you how to write to the CSV file:

    out.WriteLine("data 1, data 2, data 3")

    Replace the content in the parenthesis with your own data. Repeat this step until you write all the data you want to save to the CSV file.

  6. 6

    Close the file. After you finish writing to the file, you must close it in the code. Add the following code to close the file:


Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.