Класс EmailDocumentConverter
В этом разделе
Содержит методы, позволяющие конвертировать документы электронной почты (.msg, .eml).
Объектная модель
Синтаксис
'Declaration
Public MustInherit NotInheritable Class EmailDocumentConverter
public static class EmailDocumentConverter
public __gc abstract __sealed class EmailDocumentConverter
public ref class EmailDocumentConverter abstract sealed
Пример
Вот C#/VB.NET код, который демонстрирует, как конвертировать документ электронной почты в DOCX документ.
''' <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
/// <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);
}
Иерархия наследования
System.Object
 Vintasoft.Imaging.Email.EmailDocumentConverter
Требования
Целевые платформы: .NET 11; .NET 10; .NET 9; .NET 8; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5
Смотрите также