How to convert an HTML document file to text (TXT) in C# .NET Framework

Writing the proper code to convert file formats is about as annoying as it gets. Let’s face it, you are looking for the easy way out, right? Well, you came to the right place. You’ll be done in minutes.

Let’s start things up by using NuGet to install our API Client. This is done by running this command in the console of Package Manager.

Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 2.2.0

With that done, all that’s left is to call our ConvertDocumentHtmlToTxt function, as you see below:

using System;using System.Diagnostics;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Api;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Client;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Model;namespace Example{public class ConvertDocumentHtmlToTxtExample{public void main(){// Configure API key authorization: ApikeyConfiguration.Default.AddApiKey("Apikey", "YOUR_API_KEY");// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// Configuration.Default.AddApiKeyPrefix("Apikey", "Bearer");var apiInstance = new ConvertDocumentApi();var inputFile = new System.IO.Stream(); // System.IO.Stream | Input file to perform the operation on.try{// HTML Document file to Text (txt)TextConversionResult result = apiInstance.ConvertDocumentHtmlToTxt(inputFile);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling ConvertDocumentApi.ConvertDocumentHtmlToTxt: " + e.Message );}}}}

Done! If you like how much time this approach saves, you might like to look at some of our other API functionality, which covers everything from file editing to text recognition.

Image for post
Image for post

Written by

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store