Article: Building Custom Office Solutions with VSTO SE

Overview:   Custom Application Development with MS Office. How does one integrate Office applications with existing websites, web services and other applications?

Business Case
Arbutus really likes its knowledge management solution, but realizes that most professionals use MS Office to perform their daily business communication.  As a result our group wanted to explore the idea of extending Office applications (e.g. Outlook) so that common information could be synchronized with the Joint Contact platform.  


What is Joint Contact?
Joint Contact (www.jointcontact.com) is a hosted web-based knowledge management solution that supports the management and creation of documents, discussions, calendars, tasks and team information. Owned and operated by Arbutus Software, Joint Contact supports companies in their efforts to maintain "high trust" person-to-person (P2P) and business-to-business (B2B) relationships.   To see an online demo of Joint Contact visit www.jointcontact.com/demo.

Joint Contact


Using MS VSTO 2005 SE, this example demonstrates how to develop a MS Outlook 2007 Add-In that posts an article on to Joint Contact from an email message.

Creating an Outlook 2007 Add-In
Interacting With the Existing Web Application
Ribbons
Forms
Capturing Outlook Events
Menu Items
Add-In Deployment

Creating an Outlook 2007 Add-In
The first step is to create the Outlook Add-In, and this is actually very simple through VSTO. Notice from the screenshot that there are other Office Add-In options available.

Outlook Add-In


Interacting With the Existing Web Application
Communication between the Outlook Add-In and the web application will be achieved through web services. It is important to note that there are many ways to communicate with the web application; this is just one solution. The first step to creating a web service is to create the web service functionality in the existing web application solution.

In the web service code file, functions are created, which are later accessed in the Outlook Add-In. Note the <WebMethod()>_ code added before the sample function. This code is required before each function in the web service.

At this point, it is important to decide what functions you will need in your web service to make your Add-In work, and then implement these functions in the web service code file. In the Arbutus example, the option of inserting an article is needed so a function is implemented. This web service function will call an existing function; this makes implementation simple since code can be reused.

<WebMethod()> _

Public Function ArbutusInsertArticle(ByVal IN_Workspace As String, ByVal IN_Description As String, ByVal IN_Title As String, ByVal IN_ProfileID As Integer) As Integer

Dim obj As New ArbutusDataFactoryCls

Dim result As Integer = obj.ArbutusInsertArticle( ...

Return result

End Function

Once the functions have been implemented in the existing web application solution, the reference to the web service is added in the Add-In solution. This is done by right clicking on the Add-In solution name and selecting Add Web Reference.

Ribbons
One of the exciting new features in MS Outlook 2007 is the ability to customize a UI called Ribbons. Ribbons can be customized with many different form objects such as buttons, combo boxes, and much more.

Ribbon UI


After we add a new ribbon handler to our Add-In solution, it will create two new files (Ribbon1.vb and Ribbon1.xml). The .vb file is the code file in which the ribbon events are handled. The .xml file contains information about the Ribbon’s visual properties.

Now there is a decision to be made on which window the Add-In tab should be added into. In MS Outlook, there are many windows the Add-In can be added to. Some possibilities include the Compose Mail window, the Compose Calendar Event window, etc. Once this is decided, the Ribbon ID is needed and added in Ribbon1.vb. The Outlook Ribbon IDs can be found at http://msdn2.microsoft.com/en-us/library/bb226712.aspx

In the Arbutus example, the Add-In is added into the Compose Mail window; the Ribbon ID used here is Microsoft.Outlook.Mail.Compose. The next step is to change the Ribbon1.xml file to customize the Ribbon UI.

Public Function GetCustomUI(ByVal ribbonID As String) As String _ Implements Office.IRibbonExtensibility.GetCustomUI

Select Case ribbonID

Case "Microsoft.Outlook.Mail.Compose" Return GetResourceText( _ "SimpleOutlookRibbon.MailComposeRibbon.xml")

Case "Microsoft.Outlook.Contact" Return GetResourceText( _ "SimpleOutlookRibbon.ContactRibbon.xml")

...

End Select

End Function

Joint Contact Ribbon UI


Forms
The main purpose for this form is to interact with Joint Contact and configure user settings. The form consists of two textboxes for username and password, and a dropdownlist that displays the available workspaces from Joint Contact database.

Inside the form’s code file, form click events are handled. This particular function handles the event when the ‘Test Connection’ button is clicked. Based on the user’s input, it will check the Joint Contact database for the user’s account. If the user information is correct, the form will return a message box telling them connection was successful.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim account As String = txt_account.Text.Trim()

Dim password As String = txt_password.Text.Trim()

Dim result As Integer = 0

'create webservice proxy

Dim webservice As New Global.SimpleOutlookRibbon.arbutus.webservice

Dim RibbonHandlerObj As New Global.SimpleOutlookRibbon.RibbonHandler()

'set the webservice url webservice.Url = RibbonHandlerObj.GetServiceURL() ...

End Sub

Joint Contact Form in Outlook 2007


Capturing Outlook Events
When the user sends an email, we want to capture that event and check if the user wants to post this e-mail as an article. In the case where the user does want to post the e-mail as an article, we call the web service function to insert the e-mail as an article. We take the mail item object and extract its subject for article title and the body for the article body. After a successful post, the add-in will display a confirmation message box.

Private Sub Application_ItemSend(ByVal Item As Object, ByRef Cancel As Boolean) Handles Application.ItemSend

'Routine to manage the contents of a sent message.

'Send the contents of a sent message to Joint Contact, based on the users preferred option. 'Obtain the users setting for articles.

'Copy the outgoing message to the default workspace if selected

Dim SettingArticles As Integer = My.Settings.ArbutusSettingArticleIND If SettingArticles = 1 Then Dim myMailItem As Outlook.MailItem = TryCast(Item, Outlook.MailItem)

Dim body, subject As String

Dim ProfileID As Integer

Dim result As Integer = -1

'Retrieve the body and subject from email

body = myMailItem.HTMLBody

subject = myMailItem.Subject

...

End Sub

Confirmation after a successful post to Joint Contact articles

 


Post article on Joint Contact


Menu Items
To add more customization to the Outlook Add-In, a top-level menu item was created to extend Joint Contact. This was done by first getting the top-level menu object, then adding a CommandBarPopup object to the menu object. The menu items act like a button so click events need to be handled in order it to behave properly.

Private Function AddMenuItem()

'Grab the Outlook menu bar item

Dim menuBar As Office.CommandBar = Me.Application.ActiveExplorer.CommandBars.ActiveMenuBar

'Get the index of "Help" so we can set our menu item to be before "Help"

Dim helpMenuIndex As Object = menuBar.Controls("Help").Index

'Add "Joint Contact" to top level menu items

Dim topMenu As Office.CommandBarPopup = CType(menuBar.Controls.Add(Office.MsoControlType.msoControlPopup, Type.Missing, Type.Missing, helpMenuIndex, True), Office.CommandBarPopup)

...

End Function

Joint Contact menu item


Add-In Deployment
There are many options for deployment of the Outlook Add-In, but the simplest option is to use the setup file when we first created the Add-In. The set up file can be viewed in the solution explorer and has many options for customization. Once the setup solution is built, a MSI setup file will be generated and can be used for installation of the Add-In.

Conclusion
Creating custom a MS Office Add-In is an excellent solution to extending your existing web application to your users. Since most users already MS Office, users are able to use a technology they are already comfortable with.

Online Resources
MSDN Article Deployment for VSTO 2005 SE:
http://msdn2.microsoft.com/en-us/library/bb332051.aspx
VSTO Outlook: the Complete Setup Solution:
http://weblogs.asp.net/mnissen/articles/427504.aspx
VSTO 2005 SE Download:
http://www.microsoft.com/downloads/details.aspx?familyid=5e86cab3-6fd6-4955-b979-e1676db6b3cb&displaylang=en
VSTO Forums on MSDN:
http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=16&SiteID=1
Ribbon Extensibility Overview:
http://msdn2.microsoft.com/en-us/library/aa942866(vs.80).aspx

Looking for more information? Sign-up for our free bi-weekly newsletter. You'll be notified as new articles, case studies, tutorials and presentations become available.

who we are

Arbutus Software is a premier development firm that provides state-of-the-art custom software applications. Our vision is to help shape technology to meet business challenges by increasing workplace productivity and streamlining automation.

What we do

As a Microsoft Certified Partner, we specialize in custom application development using Internet, database and MS Office technologies. Serving Puget Sound businesses for the past 4 years, Arbutus works with companies of all sizes.

Free Newsletter!

Sign-up for our free newsletter. You'll be notified as new articles, case studies, tutorials and presentations become available.