Outlook 2013 VSTO Addin - How to check if the Mail view is selected? - outlook

In an Outlook 2013 VSTO addin (C#), I can check to see if the user is currently in the Calendar area/view by using "if(ActiveExplorer().CurrentView is CalendarView) ..."
How do I do something similar to check and see if the user is in the Mail view, where "Mail" is selected/blue at the bottom of the Outlook window and the user sees their Inbox items? There is no MailView type, or anything similar that I could find, to compare ActiveExplorer().CurrentView, etc., against.

Instead of using the CurrentView property of the Explorer class I'd suggest checking the DefaultItemType property of the Folder class. It returns a constant from the OlItemType enumeration indicating the default Outlook item type contained in the folder.
The CurrentFolder property of the Folder class returns a Folder object that represents the current folder displayed in the explorer. So, the code may look like the following one:
ActiveExplorer().CurrentFolder.DefaultItemType

Related

Outlook Add in not properly initialised when called from "Send to" Windows contextual menu

I work on an Outlook 2016 add-in (C# visual studio 2017 on Windows 10).
The add-in do its job perfectly when a new message is created and then sent from the "Write new message" window launched from the Outlook main menu (or toolbar) : the add-in displays its own ribbon with some radiobuttons to configure the message to be sent and that's all.
But when a new message window is created from the Windows contextual menu "Send to" on a file (to be sent as an attachement), the add-in is ignored : the radio buttons, even if they trigger their respective callbacks and so configure the underlying model, let the new message unchanged :-(
The main difference observed under debugger is :
from the outlook menu : the "ThisAddIn" class seems to retrieve a wrapper for the new message window and so the configuration is taken into account when the message is sent :-)
from the Windows contextual menu : only a "GetCustomUI" callback is triggered and so the message is sent unchanged when the "Send" button is clicked :-(
Any help (examples, documentation, howto, ...) appreciated ...
JF
Not all event handlers are triggered when users try to send files using the context menu Send To.
If the GetCustomUI is triggered when a user sends files from a folder (using a context menu) you can add a custom ribbon UI with your radio buttons to configure the message to be sent. I suppose that is all what your add-in does.
You just need to use Ribbon XML to create a custom UI and use the GetCustomUI function to return it back. Read more about that in the Walkthrough: Create a custom tab by using Ribbon XML article.
In the ribbon event handlers you need to make sure you get access to the item through the Context passed as an argument. For example, the onAction callback has the following signature:
C#: void OnAction(IRibbonControl control)
VBA: Sub OnAction(control As IRibbonControl)
C++: HRESULT OnAction([in] IRibbonControl *pControl)
Visual Basic: Sub OnAction(control As IRibbonControl)
The IRibbonControl interface instance provides the Context property which represents the active window containing the Ribbon user interface that triggers a callback procedure. So, you may cast it to the Inspector or Explorer for retrieving the actual mail item you have to deal with.

How to Detect if Office 365 web addin is installed or not?

We have a desktop app with which we want to integrate Office 365 calendar. We will have our users provide their consent by authorising the app in office 365. I wonder if I can use any specific permission and/or api that would help us know if our office 365 office.js addin is installed by that user. This works great with VSTO addin as we can get the info from system registry, however, as Office 365 addin is installed on cloud no such registry can be found and we won’t be able to know.
Exchange will create a subfolder for each installed web addin in a special folder named WebExtAddins. The folder is on the same level as the other special folders (e.g. the Inbox), but is hidden. You can see that folder (and its subfolders) in OutlookSpy (I am its author) - click IMsgStore button on the OutlookSpy ribbon, click "Open Folder", double click on the folder named WebExtAddins.
UPDATE April 2022 - it looks like Outlook no longer uses the WebExtAddins folder. Instead, the list of web addins is stored in a hidden (associated) message with the message class of "IPM.Configuration.ExtensionMasterTable" in the Inbox folder. The list is stored in the PR_ROAMING_XMLSTREAM binary property. The format of the property is not documented.
In EWS, the list of installed addins can be retrieved using the GetAppManifests operation. If you are using Outlook Object Model or Extended MAPI, your only option is parsing that blob.
For this particular case (figure out if a web addin is installed), the addin custom storage will be in a hidden (associated) message in Inbox folder with the message class of "IPM.Configuration.ClientExtension.<guid>", where <guid> is your addin's GUID. You should be able to asccess that hidden message using MAPIFolder.GetStorage("IPM.Configuration.ClientExtension.<guid>", olIdentifyByMessageClass) (where MAPIFolder is retrieved from Namespace.GetDefaultFolder(olFolderInbox))
It seems that there is no good way to check directly now. Just like you said,Office 365 add-in is installed on Cloud. Since it runs through a separate browser process (Like IE). After plug-ins are loaded, we typically see two IE processes in the process manager. Here's a detail. If your Office is 32-bit, then its core process will be a 32-bit one. You can see that if you load multiple plug-ins, the memory it uses will gradually increase. However, it is still a process.
Screenshot:
Also, if your Windows is 64-bit, it will create another 64-bit IE process which is actually a call relationship. As you can see from the diagram below, the 32-bit process is actually calling the 64-bit process.

Programmatically accessing archived mails in an Exchange folder

I am trying to access all the mails in a given folder via the ActiveX interface to Outlook 2013. I use the message API (MAPI) of Outlook to get the desired folder object.
However, when I go through all the items of this folder object, many messages are missing. Indeed, there are messages that are on the MS Exchange server that are not synchronized with Outlook because they are too old. (In Outlook, the folder ends with a link named 'Click here to view more on Microsoft Exchange'. When clicking on the link, the missing messages appear in Outlook. However they are not added to the folder object after this operation.)
How to access those messages? Is it possible via the Outlook ActiveX interface? If not, is there an equivalent interface to the MS Exchange server?
To access older (but not archived) emails, you can either
Set the Exchange account to sync all items in the Exchange account properties dialog. Outlook must be restarted.
Set the Exchange account to sync all items programmatically. You can do that using Extended MAPI (C++ or Delphi only), there is a flag that needs to be set in the MSEMS store profile section (the property tag is 0x66490003). Redemption (I am its author - any language) exposes the RDOExchangeMailboxStore.MonthsToKeepOffline / DaysToKeepOffline properties. Outlook must be restarted.
Open the parent folder in the online mode using the MAPI_NO_CACHE flag when calling IMsgStore::OpenEntry (Extended MAPI, C++ or Delphi only). Redemption (I am its author) lets you pass that flag when you open the folder using RDOSession.GetFolderFromID from any language.

Outlook addin has failed to find Office control by ID

I've just built an MS Outlook Add In using Visual Studio and Office 2010. I've installed it ok on 4 machines, but one user is getting the following error -
Error found in Custom UI XML of "...."
...
...
Failed to find Office control by ID
Everyone is running Windows 7 and Outlook 2010 - not sure why this person is having a problem. Can anyone suggest how to diagnose this?
For those having similar issues, you don't have to remove any add-in.
What is happening is: Outlook will try to load all ribbons (found in your ribbon xml) into any window the user goes to. Then it'll complain about not finding ID x or y.
Just make sure your GetCustomUI method in Ribbon.cs does not load the entire ribbon XML at once but rather loads it per fragment.
If you're not sure what IDs you need to target, use a breakpoint in GetCustomUI then start Outlook, surf different views (main, new email, new appointment, calendar...etc) in order to gather the IDs for the views wherein you need to show you add-in.
In my case, I needed Microsoft.Outlook.Explorer, Microsoft.Outlook.Mail.Compose and Microsoft.Outlook.Appointment.
Therefore I changed my GetCustomUI to:
public string GetCustomUI(string ribbonID)
{
switch (ribbonID)
{
case "Microsoft.Outlook.Explorer":
return GetResourceText("MyAddin.RibbonsForOutlookExplorer.xml");
case "Microsoft.Outlook.Mail.Compose":
return GetResourceText("MyAddin.RibbonForOutlookMailCompose.xml");
case "Microsoft.Outlook.Appointment":
return GetResourceText("MyAddin.RibbonForOutlookAppointment.xml");
default:
return null;
}
}
Of course, I had to break down my Ribbon.xml into the three XML files mentioned above. The result: Outlook will ONLY load the fragment needed for a given screen (appointment, new email ...) and will not complain about "not finding an ID on screen X or Y".
Finally, for those who are not sure why some users get that error while others don't: it's because of "Show add-in user interface errors" option (in Options -> Advanced). If that is unchecked then Outlook will ignore the malformed ribbon XML errors. If it checked, users will get related errors about your add-in (if any exists) and also about other add-ins.
If it works for everyone except one user. As #Brijesh Mishra mentioned check if the user has got any other addin and if he is having own quick access tool bar customized.
If he has got any of this then, remove the other addins and try to install or reset the quick access tool bar customization.
For all of you that use a Designer-based VSTO plugin, and not the XML solution.
I searched all the web for this problem, but only found XML-based solutions.
There's nothing for Visual Designer on the web, because in this case you don't have to override the "GetCustomUI" method.
Ribbons designed by using the Visual Designer return a RibbonManager by default.
This RibbonManager object represents all Ribbon (Visual Designer) items in the project and is automatically handled in background through the active window inspector.
So you don't have to write any special code to handle different windows.
To configure it correctly you just have to:
Add one extra Visual Designer Ribbon for every window the user goes to
in the Ribbon Object go under "RibbonType", open the checkbox list an only activate the corresponding window, where the ribbon should appear.
If there is more than one window checked in the list, Outlook trys to insert the ribbon in all the marked windows. Even if the corresponding window is currently not opened. That's the reason, why the error "Failed to find control ID" appears.
the actual fix for me was to separate the ribbon XML files containing the customUI and redirecting to the correct one in the GetCustomUI method (implemented using Office.IRibbonExtensibility)
in example:
public string GetCustomUI(string RibbonID)
{
switch (RibbonID)
{
case "Microsoft.Outlook.Mail.Read":
return GetResourceText("namespace.type1.xml");
case "Microsoft.Outlook.Mail.Compose":
return GetResourceText("namespace.type2.xml");
default:
return null;
}
}

Outlook 2007 Add-in form containing form with ActiveX control stuck in one off state

I have an add-in that contains a DLL and an OCX control, built in VB6. Each is separate, meaning that the add-in consists of Addin.DLL and Addin.OCX. The add-in uses a custom form, which is built off of the IPM.Appointment form in Outlook. It is deployed to the user's machine as an OFT file and is published to their Presonal Forms Library in the initial OnConnection of the add-in.
I was having issues with the form being stuck in a one off state, which required me to add code similar the following to my AppointmentItem Write and PropertyChange class:
Private Sub AppointmentItem_PropertyChange(ByVal name As String)
On Error GoTo ErrorHandler
Select Case name
Case "MessageClass"
Dim strGuid As String
' Check to see if this is one of our appointmentitems.
If IsItemUserItem(AppointmentItem_PropertyChange, strGuid) Then
' Change to our add-in message class. IPM.Appointment.XXX
AppointmentItem.MessageClass = gFormMsgClass
End If
End Select
done:
Exit Sub
ErrorHandler:
Trace "Error writing appointment item."
Resume done
End Sub
This works for most cases. However, I'm still running into instances where when I check the item during the NewInspector event if it is an Exception I cannot access UserProperties, which are used to facilitate data sharing between the DLL and OCX.
Additionally when trying to edit the form in the form designer, I cannot save the form as an OFT from Outlook 2007. I'm kind of at a loss as to what is going on with this...Any help is appreciated.
Actually it appears I have my own answer. There were some user-defined properties added to the folder that were not added to the item and they were causing the one off issues.

Resources