|
|
Want to know more about Packt's Article Network? Interested in contributing your article ideas? Please visit our FAQ for more information. See More BROWSE
All Titles WordPress Web Services SOA BPEL Web Graphics & Video Web Development RAW Portugues, Espanol, Italiano, French PHP/MySQL Oracle Open Source Networking & Telephony Moodle Microsoft & .NET Linux Servers jQuery Joomla! JBoss Java e-Learning e-Commerce Dynamics Drupal CRM Cookbook Content Management Beginner Guides Architecture and Analysis AJAX Future Titles Recently Published Titles Primarily, the Microsoft Office Outlook serves as an email application for a wide range of users. In the previous part of the article, we took an Overview of the Outlook object model and its features in VSTO. We saw the extensibility of Microsoft Office Outlook 2007 using the object model. We also learned to customize Microsoft Office Outlook menus and toolbars using VSTO. In the last part, we worked with form regions in Outlook, how to manipulate folders, contact information, and mail items using VSTO programming. In this article by Vivek Thangaswamy, we will take a look at the following topics:
See More |
Microsoft Office Outlook Programming Using VSTO 3.0 and C#: Part 1
Microsoft Office Outlook object model overviewProgramming in Microsoft Office Outlook differs from programming other Microsoft applications such as InfoPath and Excel. Most of the Microsoft Office applications target documents rather than data items, but Microsoft Office Outlook targets each data item stored in the database or the primary data storage used by an Outlook application. Microsoft Office Outlook stores and manages data items such as emails, appointments, notes, tasks, and contacts in tables in a structured database. The Microsoft Office Outlook object model is based on COM (Component Object Model) and is used to interact with Outlook form regions, menus, and other application customization possibilities. It is similar to other Microsoft Office application object models when thought of with respect to the object model implementation interfaces for collections, objects, properties, methods, and events. COM is a language-neutral way of implementing objects that can be used in different environments. A large numbers of objects are available for developing and customizing Outlook 2007. If the developer needs to develop application add-ins for Outlook, he or she can program using the objects provided by the Outlook object model. In the Outlook object model, the class will represent each object in the UI to the user. For example, the Microsoft.Office.Interop.Outlook.Application class represents the entire application, and the Microsoft.Office.Interop.Outlook.MailItem class represents an email message. To get used to the object models in Outlook, you should be familiar with some of the top-level objects. The Application object represents an Outlook application, and it is the highest level class in the Outlook object model. The Explorer object corresponds to the window that displays the contents of a folder, and contains Outlook data items such as email messages, tasks, appointments, and so on. The MAPIFolder object represents the folder that contains emails, contacts, tasks, and other Outlook data items. By default, there are sixteen MAPIFolder objects available. The Inspector object corresponds to a window that displays a single item such as a particular email message, or a specific contact item. Let's see how to create application-level add-ins for Microsoft Office Outlook 2007 using VSTO 3.0. We will create a Hello World application-level example for Microsoft Office Outlook 2007 using Visual Studio 2008.
The result will be similar to what is shown in the following screenshot:
Outlook 2007 object models are categorized and mapped correspondingly. The following Outlook object models hold all of Outlook's objects for programming in their corresponding object model categories: Items object model, Navigation bars and Outlook bars object model, Rules object model, and Views object model. In the Application object model hierarchy, the Application object is the parent of all other Outlook objects. Customization using VSTOMost enterprise business applications are loaded with a wide variety of features for users. Even though these applications have a wide range of features, many business requirements can be fulfilled only through customization because not all applications are designed to fit each and every enterprise's special needs. Customization for most of the application is a tough job to execute. Outlook 2007 is loaded with a wide variety of features that will satisfy a broad range of user categories. Some organizations need more functionality and features to be added, so that the application will satisfy their custom business requirements. VSTO 3.0 helps Office developers to customize and enhance the Outlook 2007 application as per the user's business requirements. Microsoft Office Outlook 2007 supports other Microsoft Office tools such as InfoPath and Excel, in order to provide seamless collaboration. VSTO provides an easy way to create an application-level add-in for Outlook 2007 using Visual Studio 2008. Creating add-ins for Microsoft Office Outlook 2007 has been more complex to work out, but VSTO 3.0 offers Office developers with project templates in Visual Studio 2008 to allow them to create add-ins for Outlook 2007. Adding to the project templates, VSTO offers great support for development and deployment, which improves the development work. This provides .NET framework support for Outlook 2007 add-in programming, which includes class library support, controlled exception handling, memory management, extensibility, ClickOnce deployment, and so on. Menus in OutlookA group of commands or lists of options from which you can choose your desired operation is known as a menu. Most of the latest applications are menu driven. Microsoft Office Outlook, which is a menu-driven application, provides the user with an easy fl owing UI for user interaction. Most of the menu-driven applications will provide you with basic customization such as choosing the menu for the default view of the application, and so on. In Microsoft Office, all menus and toolbars are CommandBars. A CommandBar is a static collection shared by all Windows. There are standard toolbars, menu bars, context menus, and so on. A small add-in enumerates and displays all Microsoft Outlook CommandBars. Likewise, Microsoft Office Outlook 2007 provides the option for a user to customize the menus. VSTO 3.0 provides Office developers with the ability to build custom menus and customize the existing menus using the .NET framework and support a programming language. You can even rebuild the classic menu style for Outlook 2007 by using the VSTO 3.0 application level add-ins development. Let's create a custom menu in the menu bar of the Outlook and add a new item to the menu. This way, you will get to know about custom menu development for Microsoft Office Outlook 2007. Open Visual Studio 2008 and create a new solution, as described in the previous example. Let's write a program to create a menu item and call it Say Hello World. // Defining new Menubar The following screenshot displays the resulting menu developed by you using the preceding code:
You can also build more custom menus for your Outlook 2007 with functionality as per your requirements. VSTO will speed up development and provide support for a hassle free environment for the developer to work on Outlook 2007 add-ins and other customization. Toolbars in OutlookGenerally, toolbars provide easy access to the functionality of the application by using buttons and menus. Most application's user interfaces have a toolbar that has buttons, menus, and input or output control elements for user interaction with the application. Even applications allow users to do visual customization of toolbars as per the users' needs. Microsoft Office Outlook 2007 provides a very good visual representation of toolbars for user interaction with the application. Outlook provides support for toolbar customization to improve custom visual interaction for users. VSTO 3.0 offers wide options to build custom toolbars and to customize existing toolbars as per the user's needs. Remember that menus and CommandBars are not VSTO features, but are in the Microsoft.Office namespace. VSTO is making it easier to program for the Office object model. Let's see a demonstration of creating a custom toolbar with a button.
The following image shows the results of adding a custom toolbar with button control:
The CommandBars object helps you to build variants of toolbars to your Outlook 2007 application's user interface. Microsoft Office Outlook 2007 is the only tool in the Microsoft Office 2007 family to support both standard toolbars and the new Ribbon in their UI. VSTO 3.0 for Office 2007 Programming
Outlook form regions supportBefore the release of Microsoft Office Outlook 2007, Outlook forms were the only option for creating a custom UI. In Outlook 2007, you have a new feature called form regions. Form regions are a new way of customizing the Outlook. Form regions are the added feature of the UI in the standard Microsoft Office Outlook 2007. Form regions will add custom functionality–they will build a new range of options in the UI for Microsoft Office Outlook 2007. When you work with standard forms, you can see that all Outlook items have a MessageClass property that determines the type of objects you're working on, for example, contact, appointment, task, email, post, or journal entry. All of the standard forms are stored in the standard forms library. Form regions are the replacement for the standard forms, to display the custom reading pane, and add new pages to Outlook. In form regions, the controls can be bound to the Outlook properties. Outlook forms bring you a new design with the support of .NET controls, in order to easily integrate with your Visual Studio Designer and provide code templates and debugging options.
The addition and execution of the preceding code results in the following screenshot:
One of the key advantages of form regions is that you can use themed controls that match the look of standard Outlook forms in Outlook 2007, and you also have easy access to new controls for date and time picking, and time zones. Form regions will help you to build custom contact forms, meeting invitees, and enhanced UI for Microsoft Office Outlook 2007. Outlook 2007 also contains a huge number of new form controls that offer the business logic and performance that users expect from Outlook forms. ManipulationManipulation is an essential element for the efficient development of a reliable solution to satisfy any kind of business need. Manipulation plays the most important role in customization and development of any kind of solution for mature enterprise applications. The primary part of manipulation is the data. Microsoft Office Outlook 2007 allows a wide range of data item manipulation methods inside the application—you can manipulate mail items, contact items, folders in Outlook, and so on. Let's see some examples of manipulation. FoldersFolders are the containers that hold file items and sub folders inside the main folder. Folders are used to manage mail items to make them easily accessible inside Outlook. In Outlook 2007, you can manage mail items, contact items, and other communication information.
We can see the dynamically-created folder named FolderPacktPub on the leftmost side of the Outlook screen, as shown in the following screenshot:
The folders contain Items collections which hold items that are compatible with the type of data that is supported in Microsoft Office Outlook 2007. The GetDefaultFolder() method is used to retrieve a reference to the Sent Items folder. This is declared in order to get default folders by using new Folder objects for Outlook 2007. You may need to clean up Outlook by deleting unwanted folders. The delete operation for folders inside Outlook can be performed by using the MAPIFolder object and the properties and methods exposed by the object. Let's see an example of how to delete a folder using the VSTO object. In this example, you are going to run the operation at the initialization of the add-in. You can do the same thing by using the Click event for the button that was placed on the toolbar (or anywhere else you need). Open Visual Studio 2008 and create a new solution, as explained earlier. Write the following code, which will dynamically delete a folder in the ThisAddIn.cs file: private void ThisAddIn_Startup(object sender, System.EventArgs e) Books from Packt
ContactsContacts contain information about communication with a person. The information can be their address, name, phone number, and other relevant information. The Contacts folder in Microsoft Office Outlook 2007 is the electronic form of managing contact information about people. Outlook offers the ability to very easily manage multiple phone numbers and more information for a single person. Outlook provides better management of contact entries and brings easy access through the information available in the Contacts folder. In certain situations, you may need to add or modify the contact entries dynamically. To support these features, Microsoft provides a solution through VSTO 3.0 programming to allow Office developers to build application-level add-ins, which will help you integrate custom developed solutions. We will now create a contact item using the VSTO 3.0 object model and C#. Open Visual Studio 2008 and create a new solution, as explained earlier. Write the following code, which will dynamically create a contact item in the ThisAddIn.cs file. private void ThisAddIn_Startup(object sender, System.EventArgs e) After executing the source code, you will get the following screenshot as the output for your solution.
ContactItem is the object used to access the contact in a Contacts folder by using Outlook programming. The ContactItem object has been exposed with a wide variety of properties, events, and methods to program for the Contact folder in Outlook 2007. You have seen how to create a new contact item by using an object in Outlook 2007. Let's take a look at one of the most important contact management features in Microsoft Office Outlook: the distribution list. A distribution list is a collection of email contact information that has been grouped into a single list. VSTO helps Office developers create and modify distribution lists by using the DistListItem object. Let's create a distribution list dynamically, using the VSTO Outlook object model and C# programming. Open Visual Studio 2008 and create a new solution, as described earlier. Write the following code, which will dynamically create a distribution list, inside the ThisAddIn.cs file: private void ThisAddIn_Startup(object sender, System.EventArgs e) The newly-distribution list appears as shown in the following screenshot:
On clicking the Members tab in the solution, we get a list of the recipients, or members, as shown in the following screenshot:
Email messagesEmail is an electronic form of storing information that can be shared with people via an electronic communication system. You can write, send, and receive information without using paper, and communicate through electronic systems by using a digital copy of the information. You can do many email operations through VSTO programming, such as composing mail items at runtime using Office objects. Let's create a new mail that has a Subject, To, Address and few other properties, by using the VSTO Outlook MailItem object. Open Visual Studio 2008 and create a new solution, as explained earlier. Write the following code, which will dynamically create a mail item, inside the ThisAddIn.cs file: private void ThisAddIn_Startup(object sender, System.EventArgs e) The results of the execution of the preceding code example can be seen in the following screenshot:
The Microsoft.Office.Interop.Outlook.MailItem class represents an email message. MailItem objects are usually found in folders, such as Inbox, Sent Items, and Outbox. The MailItem exposes properties and methods that can be used to create and send email messages. With Outlook 2007 mail items, you have the option to categorize mail using colors. This categorization can be achieved by the use of VSTO objects. Mail items can be categorized programmatically. Outlook.MailItem is the object used to access mail items in Outlook 2007. The following image is a typical view of the category option available in Outlook 2007:
Let's see in an example of how to get the category property by using the VSTO objects for the mail items. Open Visual Studio 2008 and create a new solution, as described earlier. Write the following code to the context menu item in the mail box folder, inside the ThisAddIn.cs file: private void ThisAddIn_Startup(object sender, System.EventArgs e) After executing this program, we can see the different color properties, as shown in the following screenshot:
VSTO also supports the customization of Outlook 2007 context menu items. Let's look at an example to add a custom menu item in the context menu item of the email folder in Outlook. Open Visual Studio 2008 and create a new solution, as explained earlier. Write the following code to the context menu item in the mail box folder, inside the ThisAddIn.cs file: privat e void ThisAddIn_Startup(object sender, System.EventArgs e) The resulting custom menu item in the Inbox mail folder is visible in the following screenshot:
SummaryThis article examined some important topics regarding programming using VSTO and C# for Microsoft Office Outlook 2007. You have seen the Outlook object model, and how it is used for Outlook application development and customization. This article covered the concepts of customizing the Outlook toolbar and menu bar using VSTO. You have learned about VSTO programming support for Outlook form regions. We have seen the most important part of Outlook data manipulation such as email, contacts, and folder manipulation. We have also seen code examples for each topic, which makes it easier to understand the concepts. The second part of this article will cover Working with Appointments and meetings and also explain with an example, how to create a Ribbon menu for Outlook 2007. VSTO 3.0 for Office 2007 Programming
About the AuthorVivek Thangaswamy Vivek Thangaswamy is a Software Solution developer and technical author living and working in the enjoyable surroundings of Chennai city, in India. His range of technical competence stretches across platforms and lines of business, but he specializes in Microsoft enterprise application architectures and Microsoft server-based product integrations. Vivek is currently working for the world's largest software services company in Microsoft Technologies. He holds several Microsoft certifications and Microsoft MVP awards. He has completed his Bachelor of technology degree in Information Technology from one of the world's finest universities and is currently pursuing a Management of Business Administration in Finance degree. Vivek loves spending time with friends and writing poems in his mother tongue. Books from Packt
|
TOP TITLES ![]()
|
| ||||||||