简体   繁体   中英

How to Open Outlook file attachment directly not saving it? ( with C# VSTO)

I need to open mail file attachment directly from mail. Let say I have.txt file. I have already attached it to my mail. But now I need to open it, change some words and save it (it is manual part). How can I do this? My code is:

private void button2_Click(object sender, EventArgs e)
        {
            Outlook.Inspector currInspector = null;
            Outlook.MailItem mail = null;
            Outlook.Attachments attachments = null;



            currInspector = Globals.ThisAddIn.Application.ActiveInspector();
            if (currInspector != null) { 
            mail = (Outlook.MailItem)currInspector.CurrentItem;
            attachments = mail.Attachments;
            attachments.Add(@"C:\install\CSharp\tulemus.txt", Outlook.OlAttachmentType.olByValue);
               

            }

The Outlook object model doesn't provide any property or method for that. You can try to read the attached files from the cache folder maintained by Outlook. See Finding Outlook temporary folder for email attachments for more information.

Also, you can use a low-level API (Extended MAPI) where you can access the PR_ATTACH_DATA_BIN property, read more about the algorithm in the Opening an attachment article.

In addition to what Eugene suggested - use Attachment.PropertyAccessor or MAPI (C++ or Delphi) to access the PR_ATTACH_DATA_BIN property (DASL name "http://schemas.microsoft.com/mapi/proptag/0x37010102" ) - you can also use Redemption: its RDOAttach . AsText / AsArray / AsStream properties allow to modify attachment contents on the fly

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM