Convert single Outlook.msg file to .pdf after drag and drop in C #

I am writing a small PDF editing program. This program can print labels at one specific location on the first page of a PDF. Files to be edited are selected by dragging and dropping. Everything is fine, but I need to write a function that converts the file to pdf before printing the label if it is .msg. I wrote a docx to pdf conversion function and it works, but I have absolutely no idea how to convert .msg to .pdf, I am trying to do it using outlook library but cannot. This is how I convert DOCX to PDF:

Microsoft.Office.Interop.Word.Document wordDoc { get; set; }

void doc_to_pdf()
{
    Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
    wordDoc = app.Documents.Open(openFD.FileName);
    wordDoc.ExportAsFixedFormat(to_pdf(openFD.FileName), Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF);

    wordDoc.Close(Microsoft.Office.Interop.Word.WdSaveOptions.wdSaveChanges);
    app.Quit();

    Marshal.ReleaseComObject(wordDoc);
    Marshal.ReleaseComObject(app);
    openFD.FileName = to_pdf(openFD.FileName);
}

      

openFD.FileName - path to the file

And this is how I try to convert MSG to PDF

Microsoft.Office.Interop.Outlook.MailItem outMsg;

void msg_to_pdf()
{
    Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
    outMsg = //i dont know how to open here this file

    string fileName = System.IO.Path.GetFullPath(openFD.FileName);
    outMsg.SaveAs(to_pdf(openFD.FileName), Microsoft.Office.Interop.Outlook.OlSaveAsType.olMSG);
}

      

I am trying to do it in different ways, but I cannot. Can anyone do this? Or who will tell you how to do this? Please help me, this is really important.

+4


source to share





All Articles