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 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


Conclusion

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

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

You can refer to our DocIo feature tour page to know about its other groundbreaking feature representations. 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 out our 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 forumsDirect-Trac, 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