HTML files are used to display data or information in web pages. Sometimes, you may need to create an HTML file within your projects. Following such scenarios, this article covers how to create an HTML file programmatically in C#.
- Create HTML Files – C# API Installation
- Create a Basic HTML File Programmatically in C#
- Create an HTML File from URL Programmatically in C#
Create HTML Files – C# API Installation
Aspose.HTML for .NET API can be used to work with different supported file formats without needing to install any other application. You may download the DLL files from the New Releases page or use the following NuGet command:
PM> Install-Package Aspose.Html
Create a Basic HTML File Programmatically in C#
You can create an HTML file with a few method calls as explained in the steps below:
- Create an object of HTMLDocument class.
- Create a text element and append it to the document.
- Save the output HTML document.
- Save the HTML document.
The code sample below shows how to follow these steps and create an HTML file programmatically in C#:
Create an HTML File from URL Programmatically in C#
You can create an HTML file by following the steps below:
- Create an object of the Url class to specify the link.
- Initialize HTMLDocument class object while passing the Url as the parameter.
- Save the output HTML file.
The following sample code demonstrates how to create an HTML file from any online web page in C#:
Explore Aspose.HTML for .NET
You may visit the API documentation where different chapters cover other features of the API.
Get Free License
You may request a free temporary license in order to evaluate the API without any evaluation limitations.
In this article, you have learned how to create an HTML web page programmatically in C#. It explains how to create an HTML file from scratch or while using the content from an online Url. Please feel free to write to us at forum in case you have any ambiguity.