Articles in this section
Category / Section

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

1 min read

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

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

HTML conversion

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

C#

// Loads an existing Word document.
WordDocument wordDocument = new WordDocument(filePath);
// Creates a new MemoryStream to save the 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 a new MemoryStream to save the Word document.
Dim stream As MemoryStream = New MemoryStream()
' Saves and closes the WordDocument instance.
wordDocument.Save(stream, FormatType.Html)
wordDocument.Close()
stream.Position = 0
' Converts 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 looks like the following:

HTML file using Essential DocIO

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

Sample


Conclusion

I hope you enjoyed learning about whether it is possible to export a Word document to a string of HTML without saving it as a file to disk.

How do I set the document page margins in WinForms DocIO.

You can refer to our DocIo feature tour page to learn about its other groundbreaking features. You can also explore our documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check explore other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied