We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Is it possible to export a Word document to a string of HTML without saving as file to disk?

Platform: WPF |
Control: DocIO

Yes, it is possible to export a Word document to a string of HTML without saving as file to disk.

Please refer the below UG link to know more about Word to HTML conversion.

HTML conversion

The following code example shows how to save a Word document template as string of HTML without saving as file.

C#

// Loads an existing Word document.
WordDocument wordDocument = new WordDocument(filePath);
// Creates new MemoryStream to save Word document.
MemoryStream stream = new MemoryStream();
// Saves and closes the WordDocument instance.
wordDocument.Save(stream, FormatType.Html);
wordDocument.Close();stream.Position = 0;
// Converts stream to string
StreamReader reader = new StreamReader(stream);
string htmlString = reader.ReadToEnd();
stream.Dispose();
reader.Dispose();
// Displays the resultant HTML string in MessageBox.
MessageBox.Show(htmlString);

 

VB

' Loads an existing Word document.
Dim wordDocument As WordDocument = New WordDocument(filePath)
' Creates New MemoryStream to save Word document.
Dim stream As MemoryStream = New MemoryStream()
' Saves And closes the WordDocument instance.
wordDocument.Save(stream, FormatType.Html)
wordDocument.Close()
stream.Position = 0
' Convert stream to string
Dim reader As StreamReader = New StreamReader(stream)
Dim HtmlString As String = reader.ReadToEnd()
stream.Dispose()
reader.Dispose()
' Displays the resultant HTML string in MessageBox.
MessageBox.Show(htmlString)

 

The output window look like as follows.

HTML file using Essential DocIO

The following sample with above codes demonstrates on how to save a Word document template as string of HTML without saving as file using Essential DocIO.

Sample

2X faster development

The ultimate WPF UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile