VintaSoft Imaging .NET SDK 15.2: Documentation for .NET developer
In This Topic
Codecs: How to convert an Email file to a DOCX file?
In This Topic
Here is C#/VB.NET code that shows how to convert an Email file to a DOCX file:
/// <summary>
/// Converts Email (.msg, .eml) document to a DOCX document.
/// </summary>
/// <param name="emailFilePath">Path to a source Email file.</param>
/// <param name="docxFilePath">Path to a result DOCX file.</param>
public static void ConvertEmailToDocx(string emailFilePath, string docxFilePath)
{
    docxFilePath = System.IO.Path.GetFullPath(docxFilePath);
    string tempHtmlFilename = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(docxFilePath), 
        System.IO.Path.GetFileNameWithoutExtension(docxFilePath) + ".html");

    // directory to save attachments
    string attachmentsDirectoryName = System.IO.Path.GetFileNameWithoutExtension(docxFilePath) + ".files";

    // convert Email document to a HTML document
    Vintasoft.Imaging.Email.EmailDocumentConverter.ConvertEmailToHtml(
        emailFilePath, tempHtmlFilename, attachmentsDirectoryName, new Vintasoft.Imaging.Email.EmailToHtmlConverterSettings());

    // convert HTML document to a DOCX document
    Vintasoft.Imaging.Office.OpenXml.OpenXmlDocumentConverter.ConvertHtmlToDocx(tempHtmlFilename, docxFilePath);

    // delete temp HTML filename
    System.IO.File.Delete(tempHtmlFilename);
}
''' <summary>
''' Converts Email (.msg, .eml) document to a DOCX document.
''' </summary>
''' <param name="emailFilePath">Path to a source Email file.</param>
''' <param name="docxFilePath">Path to a result DOCX file.</param>
Public Shared Sub ConvertEmailToDocx(emailFilePath As String, docxFilePath As String)
    docxFilePath = System.IO.Path.GetFullPath(docxFilePath)
    Dim tempHtmlFilename As String = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(docxFilePath), System.IO.Path.GetFileNameWithoutExtension(docxFilePath) & ".html")

    ' directory to save attachments
    Dim attachmentsDirectoryName As String = System.IO.Path.GetFileNameWithoutExtension(docxFilePath) & ".files"

    ' convert Email document to a HTML document
    Vintasoft.Imaging.Email.EmailDocumentConverter.ConvertEmailToHtml(emailFilePath, tempHtmlFilename, attachmentsDirectoryName, New Vintasoft.Imaging.Email.EmailToHtmlConverterSettings())

    ' convert HTML document to a DOCX document
    Vintasoft.Imaging.Office.OpenXml.OpenXmlDocumentConverter.ConvertHtmlToDocx(tempHtmlFilename, docxFilePath)

    ' delete temp HTML filename
    System.IO.File.Delete(tempHtmlFilename)
End Sub