Funny Paul
Funny Paul

Reputation: 11

VSTO Outlook Addin Get Filename from .msg File

An .msg file from anywhere in the file system is opened in Outlook. How can you determine the complete file name in a VSTO add-in?

Is there perhaps a special property that can be accessed via PropertyAccessor?

I'm desperate.

I've searched all sorts of things with the great OutlookSpy tool, but to no avail.

Upvotes: 0

Views: 38

Answers (2)

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66215

No, once a message is opened, there is no trace that it came from the file system. More than that, Outlooks does not use the original IMessage object returned from OpenIMsgOnIStg, but rather creates a temporary message in the Outlook default message store; that's the message the user interacts with.

Upvotes: 0

Funny Paul
Funny Paul

Reputation: 11

MSG file, for example (C:\something\message.msg) is opened with a double click, the event handler starts successfully

    private void Inspectors_NewInspector(Inspector inspector)
    {
        if (inspector.CurrentItem is MailItem)
        {
            MailItem mailItem = inspector.CurrentItem as MailItem;

           System.Diagnostics.Debug.WriteLine(mailItem.FileName_xyz_Propety); // <<-- Unfortunately that or something similar doesn't work

            mailItem.Subject += " " + DateTime.Now; // Change Subject for Test
            mailItem.Save(); // File with change in subject successfully written back to the file system.
        }

Upvotes: 0

Related Questions