Converting HTML to XHTML - ASP.Net | Mana Blog... for all
Aug 18, 2010

Sometimes we are in a situation that we want to convert HTML to XHTML format. You can easily achieve this using the HTML2XHTML.dll library created by Microsoft.

You can download the library at: Click here to download

Next you need to register the library. Just go to the Visual Studio.NET command prompt and go to the folder which contains the HTML2XHTMLLib.dll file and type:

regsvr32.exe  [path of HTML2XHTMLLib.dll]

Now you can use can reference the library in our application using the Add Reference feature.

The following code reads the html file and converts it into the XHTML file and save it with the different name:

public void UsingHTMLTOXHTMLConverter(string html)
FileStream fs = null;
StreamWriter sw = null;

XHTMLUtilities xhtmlUtil = new XHTMLUtilities();
string xhtml = xhtmlUtil.convertToXHTML(html);

Label1.Text = Server.HtmlEncode(xhtml);

// write a new html file which contains the xhtml code

fs = File.Create(Server.MapPath("TestingResult.html"));
sw = new StreamWriter(fs);

catch (Exception ex)

// close the filestream and close the writer