This is a simple tutorial on creating csv files using C# that you will be able to edit and expand on to fit your own needs.
First you’ll need to create a new Visual Studio C# console application, to do so follow these steps:
To create and run a console application
Start Visual Studio.
- On the menu bar, choose File, New, Project.
- Expand Installed, expand Templates, expand Visual C#, and then choose Console Application.
- In the Name box, specify a name for your project, and then choose the OK button.
- If Program.cs isn’t open in the Code Editor, open the shortcut menu for Program.cs in Solution Explorer, and then choose View Code.
Replace the contents of Program.cs with the following code.
static void Main()
// Set the path and filename variable "path", filename being MyTest.csv in this example.
// Change SomeGuy for your username.
string path = @"C:\Users\SomeGuy\Desktop\MyTest.csv";
// Set the variable "delimiter" to ", ".
string delimiter = ", ";
// This text is added only once to the file.
// Create a file to write to.
string createText = "Column 1 Name" + delimiter + "Column 2 Name" + delimiter + "Column 3 Name" + delimiter + Environment.NewLine;
// This text is always added, making the file longer over time
// if it is not deleted.
string appendText = "This is text for Column 1" + delimiter + "This is text for Column 2" + delimiter + "This is text for Column 3" + delimiter + Environment.NewLine;
// Open the file to read from.
string readText = File.ReadAllText(path);
Now when you start the program it should create a csv file called MyTest.csv in the location you specified. The contents of the file should be 3 named columns with text in the first 3 rows.
If you would like to know how to create a console application in Visual Studio that won’t open a command window when it runs see this tutorial link.