'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);
}
Solution 1:[1]
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.
Solution 2:[2]
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 (I am its author): its RDOAttach.AsText
/ AsArray
/ AsStream
properties allow to modify attachment contents on the fly
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Eugene Astafiev |
Solution 2 |