Zach Jeyakaran
Posts: 120
Joined: 2011-09-07
|
Hello,
I have an existing object model that uses MailItem objects to do work on MailItem Attachments. What I want to do now is to remove unselected attachments from the MailItem so I can process them using existing code. Here is an example of what I want to do (questions are in comments at the end of the code):
private void attachmentContextButton_OnClick(object sender, AddinExpress.MSO.IRibbonControl control, bool pressed)
{
var context = control.Context;
if (context == null) return;
insp = OutlookApp.ActiveInspector();
exp = OutlookApp.ActiveExplorer();
if (insp != null)
{
item = (MailItem)insp.CurrentItem;
}
...
...
var selectedAttachments = (control.Context as AttachmentSelection)?.OfType<Attachment>();
var attachments = selectedAttachments as IList<Attachment> ?? selectedAttachments.ToList();
foreach (var attachment in attachments)
{
// So here I know which attachments are selected. They have an index and a name.
// I need to know which attachment this is in item.Attachments so I can remove the non-selected ones
// and call the below line of code as normal. I can't find a way to associate the selected attachment
// and the one in the MailItem.
MyCustomCode.DoStuffWithAttachments(item);
}
}
I hope there is way to do this, as the alternative is going to be a lot of work...
Thanks,
Jeff |
|
Zach Jeyakaran
Posts: 120
Joined: 2011-09-07
|
Nevermind, I figured out that the index is the same order as the collection of attachments (probably where it gets seeded from). I just looped over them and I have a list of the selected ones (the ones I keep). Then I just removed what I needed from my object model.
-Jeff |
|
nwein
Posts: 577
Joined: 2011-03-28
|
|
Zach Jeyakaran
Posts: 120
Joined: 2011-09-07
|
|