May Wolfgang
Guest
|
private void adxRibbonButton1_OnClick(object sender, IRibbonControl control, bool pressed)
{
List<Attachment> AttachmentItems = GetSelectedAttachments(control);
MessageBox.Show(AttachmentItems.Count.ToString());
}
private List<Attachment> GetSelectedAttachments(IRibbonControl control)
{
if (control == null) return new List<Attachment>();
object context = control.Context;
Inspector inspector = null;
Explorer explorer = null;
AttachmentSelection selectedAttachments = null;
List<Attachment> attachmentsList = new List<Attachment>();
try
{
if (context is Explorer)
{
explorer = context as Explorer;
if (explorer != null)
{
selectedAttachments = explorer.AttachmentSelection;
}
}
else if (context is Inspector)
{
inspector = context as Inspector;
if (inspector != null)
{
selectedAttachments = inspector.AttachmentSelection;
}
}
else if (context is AttachmentSelection)
{
selectedAttachments = context as AttachmentSelection;
}
if (selectedAttachments != null && selectedAttachments.Count > 0)
{
foreach (object attachment in selectedAttachments)
{
if (attachment is Attachment)
{
attachmentsList.Add((Attachment)attachment);
}
}
}
}
finally
{
try
{
if (context != null) Marshal.ReleaseComObject(context);
if(explorer != null) Marshal.ReleaseComObject(explorer);
if (inspector != null) Marshal.ReleaseComObject(inspector);
if (selectedAttachments != null) Marshal.ReleaseComObject(selectedAttachments);
}
catch { }
}
return attachmentsList;
}
This is the Initialization of the ribbon tab:
this.adxRibbonTabAttachments.Context = "Outlook.TabSetAttachments";
this.adxRibbonTabAttachments.Controls.Add(this.adxRibbonGroup1);
this.adxRibbonTabAttachments.Id = "adxRibbonTab_54325b3eecb0484b82ee2e1d1342d1f2";
this.adxRibbonTabAttachments.IdMso = "TabAttachments";
this.adxRibbonTabAttachments.Ribbons = ((AddinExpress.MSO.ADXRibbons)((AddinExpress.MSO.ADXRibbons.msrOutlookMailRead | AddinExpress.MSO.ADXRibbons.msrOutlookExplorer)));
I have this code, but does not work(the selection is always 0) with the following scenario:
- select message
- right-click on the attachment(It seems it depends if the attachment preview was loaded one time or not)
- then click on the button from the Attachments ribbon tab
I also remarked that if I try to use the "Save As" button from the Attachment Tools, it works fine, so the selection is recognized by the Outlook.
The version that I use for tests is Outlook 2016. |
|
Andrei Smolin
Add-in Express team
Posts: 18829
Joined: 2006-05-11
|
Hello Wolfgang,
May Wolfgang writes:
I have this code, but does not work(the selection is always 0) with the following scenario:
- select message
- right-click on the attachment(It seems it depends if the attachment preview was loaded one time or not)
- then click on the button from the Attachments ribbon tab
As far as I can see an Explorer object is always supplied as the context object for a button located in a custom group on the TabAttachments from TabSetAttachments when Ribbons is OutlookExplorer. For such a button to return the attachment selection correctly, you should click an attachment in the UI to open the attachment preview. Even if no previewer exists for that attachment type, the attachment selection works correctly with a Ribbon button in Explorer.
If you show a button on the ContextMenuAttachments, its context object is always AttachmentSelection and it returns the selection correctly.
Hope this helps.
Andrei Smolin
Add-in Express Team Leader |
|
May Wolfgang
Guest
|
Hello,
I do not know if you understand which is my problem.
Can you give me an email address to send a video with my scenario and to tell me than if that is correct or not ?
Thank you |
|
Dmitry Kostochko
Add-in Express team
Posts: 2875
Joined: 2004-04-05
|
Hi Wolfgang,
You can find our support email address in the readme.txt file located in the Add-in Express installation folder. |
|
Andrei Smolin
Add-in Express team
Posts: 18829
Joined: 2006-05-11
|
|