C#

Create HTML File In Console App Using C#

In this article, I’m showing that how to create an HTML file in Console Application using c# with the example. In this demo, I’m just creating a simple HTML that shows the first and last name entered by the user.

Here is The code:

using System;
using System.IO;

namespace HtmlFileInConApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter First Name:");
            string Fname = Console.ReadLine();
            Console.WriteLine("Enter Last Name:");
            string Lname = Console.ReadLine();

            //Html Code
            string html = "<h3 style='color:#0000ff;'>First Name: </h3> <span>" + Fname + "</span>";
            html += "<h3 style='color:#0000ff;'>Last Name: </h3> <span>" + Lname + "</span>";

            File.WriteAllText(@"D:\Files\HtmlFileUsingConsoleApp.htm", html);

            Console.WriteLine("HTML File created.");
            Console.ReadLine();
        }
    }
}

Final Output:

Chand Dakhara

Web Developer

Share
Published by
Chand Dakhara

Recent Posts

Testing hk

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Operation

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

TETS NEW

test

3 years ago