In this article I will explain with an example, how to create HTML File in Console (Command) Application using C# and VB.Net.
First, an HTML Table will be generated in the form of an HTML string and then the HTML string will be written to an HTML File and saved in Folder (Directory) using C# and VB.Net.
 
 
Namespaces
You will need to import the following namespace.
C#
using System.IO;
 
VB.Net
Imports System.IO
 
 
Creating HTML File in Console Application using C# and VB.Net
Inside the Main method, the captured value of Name is wrapped into an HTML Table string and then using the WriteAllText method of the File class, the HTML string is written to an HTML File and finally, the HTML File is saved in a Folder (Directory).
C#
static void Main(string[] args)
{
    Console.WriteLine("Enter Name:");
    string name = Console.ReadLine();
 
    //Table start.
    string html = "<table cellpadding='5' cellspacing='0' style='border: 1px solid #ccc;font-size: 9pt;font-family:arial'>";
 
    //Adding HeaderRow.
    html += "<tr>";
    html += "<th style='background-color: #B8DBFD;border: 1px solid #ccc'>Name</th>";
    html += "</tr>";
 
    //Adding DataRow.
    html += "<tr>";
    html += "<td style='width:120px;border: 1px solid #ccc'>" + name + "</td>";
    html += "</tr>";
 
    //Table end.
    html += "</table>";
 
    //Create the HTML file.
    File.WriteAllText(@"E:\Files\Console.htm", html);
 
    Console.WriteLine("HTML File created.");
    Console.ReadLine();
}
 
VB.Net
Sub Main()
    Console.WriteLine("Enter Name:")
    Dim name As String = Console.ReadLine()
 
    'Table start.
    Dim html As String = "<table cellpadding='5' cellspacing='0' style='border: 1px solid #ccc;font-size: 9pt;font-family:arial'>"
 
    'Adding HeaderRow.
    html &= "<tr>"
    html &= "<th style='background-color: #B8DBFD;border: 1px solid #ccc'>Name</th>"
    html &= "</tr>"
 
    'Adding DataRow.
    html &= "<tr>"
    html &= "<td style='width:120px;border: 1px solid #ccc'>" & name & "</td>"
    html &= "</tr>"
 
    'Table end.
    html &= "</table>"
 
    'Create the HTML file.
    File.WriteAllText("E:\Files\Console.htm", html)
 
    Console.WriteLine("HTML File created.")
    Console.ReadLine()
End Sub
 
 
Screenshots
The Console Application accepting Name
Create HTML File in Console Application using C# and VB.Net
 
The generated HTML File
Create HTML File in Console Application using C# and VB.Net
 
 
Downloads