How can create a HTML file via console programming ?

How can create an HTML file via console programming?

Last updated:9/13/2019 2:26:14 AM

2 Answers

Sanat Shukla
Sanat Shukla

Step (1) - Add a new empty project.
How can create a HTML file via console programming ?
Step (2) - Add a class file (.cs)

write this code :-

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace HTML_File_Console_CS
    class Program
        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(@"C:\Users\msclient007.MSSERVER001\Desktop\Testhtml\Console.htm", html);

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

How can create a HTML file via console programming ?


using System.Reflection;

using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("HTML_File_Console_CS")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HTML_File_Console_CS")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("9bf1e99f-75df-4118-9f28-5eaa3313f454")]

// Version information for an assembly consists of the following four values:
// Major Version
// Minor Version
// Build Number
// Revision
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("")]
[assembly: AssemblyFi

How can create a HTML file via console programming ?

Create a folder on desktop for saving the Html file.