Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a file (.htm) in C#

Tags:

c#

file

I would like to know the best way to create a simple html file using c#.

Is it using something like System.IO.File.Create?

like image 577
Johan Avatar asked Oct 18 '11 08:10

Johan


People also ask

What is a HTM file attachment?

An HTM file is an HTML webpage used by web browsers, such as Google Chrome, Microsoft Edge, and Mozilla Firefox. It may contain hyperlinks and markup language, which defines the elements and layout of a webpage.

How do I open a HTML file?

Open the saved HTML file in your favorite browser (double click on the file, or right-click - and choose "Open with").

What is HTML C#?

Hypertext Markup Language is the first programming language many of us learn. Like chess, it's easy to learn but can take a lifetime to master. Its declarative syntax is ideal and ubiquitous across many different ecosystems, and C# embraces it with ASP.NET.


1 Answers

Something like -

using (FileStream fs = new FileStream("test.htm", FileMode.Create)) 
{ 
    using (StreamWriter w = new StreamWriter(fs, Encoding.UTF8)) 
    { 
        w.WriteLine("<H1>Hello</H1>"); 
    } 
} 
like image 195
ipr101 Avatar answered Sep 18 '22 22:09

ipr101