Convert Word Documents to HTML using C#

Word to HTML C#

In various cases, you need to display the content of the Word documents in your web or desktop applications. One of the suitable options in such cases is the conversion of Word documents to HTML. To achieve this from within the .NET applications, this article covers how to convert Word DOCX or DOC files to HTML using C#. Moreover, you will learn how to control Word to HTML conversion dynamically using different options.

C# API for Word to HTML Conversion

To perform Word to HTML conversion from within the .NET applications, we will use Aspose.Words for .NET. It is a powerful class library that lets you create and manipulate Word documents. Also, it allows you to convert Word documents to various other file formats. You can either download the API or install it using NuGet.

PM> Install-Package Aspose.Words 

Convert a Word Document to HTML in C#

Aspose.Words for .NET makes it quite easier for you to convert a Word document to HTML. Simply load the Word document and save it as an HTML file. The following are the steps to convert a Word DOCX file to HTML in C#.

The following code sample shows how to convert a Word document to HTML using C#.

Customize Word to HTML Conversion in C#

Aspose.Words for .NET also allows you to customize the Word to HTML conversion using different options. For example, you can specify a folder to keep the resource files (CSS, fonts, and image) separately. In addition, you can export round-trip information of the document. The following sections demonstrate how to use these options.

Export Round-trip Information in Word to HTML Conversion

MS Word provides a wide range of features and not all of these are supported by HTML. Therefore, to make the content of HTML close to the original document, round-trip information is used. The following steps show how to export round-trip information in Word to HTML conversion.

The following code sample shows how to export round-trip information in Word to HTML conversion.

Specify Resource Folder in Word to HTML Conversion

While performing Word to HTML conversion, you can save the resource files in a separate folder. Also, you can specify folders to keep fonts and images separately. The following are the steps to achieve this.

The following code sample shows how to keep resources in a separate folder in Word to HTML conversion.

Read more about working with resource folders in Word to HTML conversion.

Get a Free API License

You can get a temporary license in order to use Aspose.Words for .NET without evaluation limitations.

Conclusion

In this article, you have learned how to convert Word DOCX or DOC documents to HTML using C#. Furthermore, you have seen how to use different options to customize Word to HTML conversion. You can also explore other features of Aspose.Words for .NET using the documentation. In addition, you can post your queries on our forum.

See Also