VSTO 3.0 for Office 2007 Programming

4 (1 reviews total)
By Vivek Thangaswamy
  • Instant online access to over 7,500+ books and videos
  • Constantly updated with 100+ new titles each month
  • Breadth and depth in over 1,000+ technologies
  1. Visual Studio Tools for Office (VSTO)

About this book

With the arrival of Visual Studio Tools for Office 3.0 (VSTO), developers can now program Microsoft Office from the .NET framework. There are huge books in the market that give loads of unnecessary information but are of no real help to brand-new Office developers. Wouldn't it be great to have a precise book that simply covers the basics and introduces programming Office 2007 with VSTO using the latest version of Visual Studio? This is that book.

VSTO 3.0 for Office 2007 Programming shows you how to write Office 2007 applications with Visual Studio Tools for Office 3.0. Learn how to automate tasks in InfoPath, Word, Excel, Outlook, PowerPoint, Visio, and Project 2007 with greater programming power and flexibility than was available from the VBA language. With this book and the mastery of VSTO you will learn, Office will no longer be an application to you; it will be a platform for developing custom applications.

VSTO 3 is the most recent version of VSTO, making use of Visual Studio 2008, and working with Office 2007. This book shows how VSTO puts Office automation into the hands of developers, allowing them to use the power of the .NET framework to automate Office applications thus increasing the speed of the applications, their security, and the opportunity to use other parts of the .NET Framework such as its data handling capabilities.

This book builds a solid programming foundation in VSTO for brand-new Office developers. You will leave behind the world of VBA programming and take your first steps into the powerful and exciting world of using C# to create Office 2007 applications. Packed with examples and covering all the main Office applications, this book will have you creating fully featured Office extensions before you know it.

Publication date:
March 2009
Publisher
Packt
Pages
260
ISBN
9781847197528

 

Chapter 1. Visual Studio Tools for Office (VSTO)

VSTO is a framework for the development of solutions for Microsoft Office tools. By using VSTO and what is known as managed code, developers can build Office solutions. Before we begin the chapter, let us see an overview of what we are going to cover in this chapter. This book is for Office Developers using Visual Studio Tools for Office. This chapter will make you comfortable with Visual Studio Tools for Office 3.0. We will be covering:

  • What is Microsoft VSTO?

  • Why do we need VSTO 3.0?

  • New features added in VSTO 3.0 as compared with the older version

  • The architecture of VSTO and the tools' approaches

  • Infrastructural setup—system requirements, installation, and so on

  • How VSTO is integrated with Visual Studio 2008, and its integrated design and debugging features

  • New features in the next version of VSTO, and how VSTO can be further improved

VSTO helps you to build document-level solutions, where a solution is specific to the document for which it is deployed. You can build application-level solutions by using the application-level add-in for your solution development. The application-level add-in is accessible to all of the documents processed through that particular application.

What is Microsoft VSTO?

VSTO is a platform for Microsoft Office solution development, built on top of .NET framework. The latest release is version 3.0. Starting with VSTO 3.0, developers have integrated Office clients into the Visual Studio designer and the .NET layers on top of the native object models.

The image above represents how VSTO has been integrated with the Visual Studio 2008 environment. Now, the term "Office solutions" appears a lot. You may have questions like—"What exactly, is an Office solution anyway? What kind of Office solutions can be developed using VSTO?". Let's answer these questions.

An Office solution is a solution developed for Microsoft Office applications, including Word, Excel, InfoPath, Access, or PowerPoint. With the help of VSTO, developers can build Office solutions using what is known as managed code.

Managed code is program code that executes under the supervision of a .NET Framework Common Language Runtime. Programs in any programming language can be compiled using either managed or unmanaged code. Code that is built on the .NET framework is meant to be managed code. Managed code brings easy deployment to your VSTO solution, as compared to VBA(Visual Basic for Applications). VBA is a programming combination of Visual Basic associated with an integrated development environment for Microsoft Office applications.

Unlike VSTO, VBA doesn't support programming languages. VSTO gives you the full support of a programming language to build Microsoft Office solutions. VSTO helps you to build a secure and safe solution for your Office application. All of the VBA scripts will be stored inside the document for which you are programming, while VSTO brings you the new concept called document-level solutions and application-level solutions.

Using VSTO, Office developers can build solutions such as Add-Ins; Add-Ins are additional program components that can be added to Office applications by using VSTO. For example, Microsoft offers a few free add-ins for Office 2007 licensed users, such as the 2007 Microsoft Office add-in Microsoft Save as PDF or XPS—this add-in facilitates the saving of a document in PDF or XPS format. You can also customize existing Office application features, and you can program against existing options available in the Office application. Let's say you need to save or export all of the content from Microsoft Office Word 2007 to Microsoft Office Excel 2007 on the click event of a button placed on the toolbar, or during some action.You can create an add-in for this kind of activity using VSTO. This is one scenario where you can use a VSTO add-in for your Office solution development.

Before VSTO, Office developers had to use VBA, VB6, or C++ to create so called shared COM Add-Ins. All Add-Ins share the same address space, and if one fails, the host application or all other Add-Ins crash. Unlike VSTO, VBA code is written directly in the Office application's IDE and is compiled at run-time. All VBA scripts are stored inside the document for which you were programming. In VSTO, this is termed a document-level solution, where the solution is specific to the document for which it is deployed. Similarly, in VSTO, document level add-ins are delivered within a specific document. For example, let's say that you include functions in a specific Microsoft Office Word document—the functions are available only when you open that particular Word document. Document level add-ins are relevant only to Word and Excel. Document-level customizations are the VSTO version of VBA macros in Word or Excel.

VSTO introduces a new concept called application-level solutions. With an application-level solution, the solution is accessible for all documents processed through that particular application. You can build application-level solutions by using the application-level add-in for your solution development.

VSTO gives you two fully-supported programming languages in which to build Microsoft Office solutions that will run in all Microsoft Office applications—C#, VB.NET, or XML. As a VSTO programmer, you will need to have a basic knowledge of C# to program Office applications using C#. In this book, we will assume that you have a basic knowledge of C# concepts such as classes, namespaces, and methods. In addition, you should know the basics of XML.

Note

The following MSDN reference link will help you learn about .NET and C#: http://msdn.microsoft.com/en-us/vcsharp/aa336804.aspx

In most of the Office 2007 applications, Microsoft has used XML(Extensible Markup Language) as the standard format for data and UI processing. For example, InfoPath forms save data in XML format. C# brings you great programming support for XML and Office applications. Office already has built-in support for an XML-based customization model, of which VSTO takes full advantage. Using C# classes and simple XML, VSTO simplifies the connection between .NET, and the server and Office systems.

  • VSTO leverages two powerful technologies that you may be familiar with—C# and XML. C# is one of the most powerful programming languages supported by Microsoft .NET frameworks.

  • VSTO gives full flexibility to programs using C# and VB.NET programming language for Office 2007 applications.

  • You, as a VSTO programmer, need to have a basic knowledge of C#, in order to program Office applications using C#.

So, for instance, instead of having a Word macro that you need to run in order to create the document you want, you could simply transfer the information to a Word template and have Office create the document for you! VSTO thus provides data-caching capabilities.

 

What is Microsoft VSTO?


VSTO is a platform for Microsoft Office solution development, built on top of .NET framework. The latest release is version 3.0. Starting with VSTO 3.0, developers have integrated Office clients into the Visual Studio designer and the .NET layers on top of the native object models.

The image above represents how VSTO has been integrated with the Visual Studio 2008 environment. Now, the term "Office solutions" appears a lot. You may have questions like—"What exactly, is an Office solution anyway? What kind of Office solutions can be developed using VSTO?". Let's answer these questions.

An Office solution is a solution developed for Microsoft Office applications, including Word, Excel, InfoPath, Access, or PowerPoint. With the help of VSTO, developers can build Office solutions using what is known as managed code.

Managed code is program code that executes under the supervision of a .NET Framework Common Language Runtime. Programs in any programming language can be compiled using either managed or unmanaged code. Code that is built on the .NET framework is meant to be managed code. Managed code brings easy deployment to your VSTO solution, as compared to VBA(Visual Basic for Applications). VBA is a programming combination of Visual Basic associated with an integrated development environment for Microsoft Office applications.

Unlike VSTO, VBA doesn't support programming languages. VSTO gives you the full support of a programming language to build Microsoft Office solutions. VSTO helps you to build a secure and safe solution for your Office application. All of the VBA scripts will be stored inside the document for which you are programming, while VSTO brings you the new concept called document-level solutions and application-level solutions.

Using VSTO, Office developers can build solutions such as Add-Ins; Add-Ins are additional program components that can be added to Office applications by using VSTO. For example, Microsoft offers a few free add-ins for Office 2007 licensed users, such as the 2007 Microsoft Office add-in Microsoft Save as PDF or XPS—this add-in facilitates the saving of a document in PDF or XPS format. You can also customize existing Office application features, and you can program against existing options available in the Office application. Let's say you need to save or export all of the content from Microsoft Office Word 2007 to Microsoft Office Excel 2007 on the click event of a button placed on the toolbar, or during some action.You can create an add-in for this kind of activity using VSTO. This is one scenario where you can use a VSTO add-in for your Office solution development.

Before VSTO, Office developers had to use VBA, VB6, or C++ to create so called shared COM Add-Ins. All Add-Ins share the same address space, and if one fails, the host application or all other Add-Ins crash. Unlike VSTO, VBA code is written directly in the Office application's IDE and is compiled at run-time. All VBA scripts are stored inside the document for which you were programming. In VSTO, this is termed a document-level solution, where the solution is specific to the document for which it is deployed. Similarly, in VSTO, document level add-ins are delivered within a specific document. For example, let's say that you include functions in a specific Microsoft Office Word document—the functions are available only when you open that particular Word document. Document level add-ins are relevant only to Word and Excel. Document-level customizations are the VSTO version of VBA macros in Word or Excel.

VSTO introduces a new concept called application-level solutions. With an application-level solution, the solution is accessible for all documents processed through that particular application. You can build application-level solutions by using the application-level add-in for your solution development.

VSTO gives you two fully-supported programming languages in which to build Microsoft Office solutions that will run in all Microsoft Office applications—C#, VB.NET, or XML. As a VSTO programmer, you will need to have a basic knowledge of C# to program Office applications using C#. In this book, we will assume that you have a basic knowledge of C# concepts such as classes, namespaces, and methods. In addition, you should know the basics of XML.

Note

The following MSDN reference link will help you learn about .NET and C#: http://msdn.microsoft.com/en-us/vcsharp/aa336804.aspx

In most of the Office 2007 applications, Microsoft has used XML(Extensible Markup Language) as the standard format for data and UI processing. For example, InfoPath forms save data in XML format. C# brings you great programming support for XML and Office applications. Office already has built-in support for an XML-based customization model, of which VSTO takes full advantage. Using C# classes and simple XML, VSTO simplifies the connection between .NET, and the server and Office systems.

  • VSTO leverages two powerful technologies that you may be familiar with—C# and XML. C# is one of the most powerful programming languages supported by Microsoft .NET frameworks.

  • VSTO gives full flexibility to programs using C# and VB.NET programming language for Office 2007 applications.

  • You, as a VSTO programmer, need to have a basic knowledge of C#, in order to program Office applications using C#.

So, for instance, instead of having a Word macro that you need to run in order to create the document you want, you could simply transfer the information to a Word template and have Office create the document for you! VSTO thus provides data-caching capabilities.

 

Why VSTO 3.0?


VSTO is a simple, but powerful framework for Office solution development. The framework brings an amazing number of benefits to the hands of every Office developer—form controls, classes, granular security, server scalability, object-oriented features, integrity, easy deployment, and many others.

Safer managed code extensions

VSTO allows managed and unmanaged code to be seamlessly put together into the same .NET assembly. This allows the developers to retain unmanaged code that cannot be ported over to the .NET framework without completely re-writing it. The Microsoft Office document or workbook with a linked or referenced managed code assembly is said to have managed code extensions. Managed extensions can be created by using VSTO on Microsoft Excel or Word, which are similar to macros but are much safer. With VSTO, you can create a template that only needs to be loaded with data.

Data caching

Data caching, simply put, is storing data in memory for quick access. A Microsoft Office Word document or Excel workbook has a hidden control rooted inside it called the Runtime Storage Control, which stores cached data. VSTO provides data-caching capabilities as well as a ServerDocument class in C# that can be used by an application external to Office (for example, the Winform application) to manipulate the data cache without accessing the object model of Word or Excel.

Feature customization

VSTO 3.0 gives you great control in being able to customize Office applications with reusable classes. Unlike VBA developers, VSTO developers are not limited to the VBA function library. VSTO provides a wide variety of classes, objects, and events to build business solutions for Microsoft Office. Using VSTO, developers can customize features for Office applications. These can be as simple as a button on the application's Command bar or adding custom task panes, or as complex as a data report template with access to different data sources.

User Interface customization

VSTO provides Windows Forms controls that help you to develop a rich User Interface(UI) for your Office solution. By using a wide variety of control sets, VSTO developers can build rich data views for users. Each and every type of Windows Forms control has its own set of properties, methods, and events that make it suitable for different needs.

VSTO makes it easy to build rich User Interfaces by using controls inside the document and the Task Pane. For instance, you can create an animated one-button command to generate a form letter. For example, say a company has data content stored in its server, and a user wants to refer some content from the server while working in the document and without disturbing the current document view. Using VSTO, you can make the server content available inside the Task Pane of the document without interfering with the user's current work.

Smart tags

New for VSTO 3.0 and Office 2007, smart tags are strings that an Office application recognizes in a document. With Smart tags enabled, Microsoft Office Word attempts to recognize certain types of data in a document, visually indicated by a purple, dotted underline. Clicking on a smart tag brings up a list of possible actions for that particular data type. VSTO provides object models to Office developers, which can be used to create smart tags for documents and workbooks.

WPF support

Windows Presentation Foundation(WPF) controls is a technology product of Microsoft Corporation. WPF can be used to build a rich and attractive look and feel for the user. WPF can be used in VSTO development environment, which supports C# programming, whereas VBA lacks this support. VSTO's visual designer supports the use of Windows Forms and Windows Presentation Foundation controls. WPF provides a reliable programming model for building client-based and web-based applications, and presents a clear separation between the business logic and the UI.

Visual designers

VSTO provides visual designers for Office applications such as Word 2007, Excel 2007, and others that appear inside the Visual Studio IDE(Integrated Development Environment). Creating a form in the Visual Studio IDE is as easy as dragging and dropping the form into the Microsoft Office document. Developers gain access to many tools and features in Visual Studio's IDE, such as IntelliSense (Microsoft's implementation of auto completion in the Visual Studio IDE), drag and drop controls, and data sources. VSTO also provides the Ribbon Visual Designer that lets you customize the Office Ribbon and program it by using a simple .NET application-like programming model. The following image explains how IntelliSense helps developers using Visual Studio IDE.

Security improvements

The VSTO security model involves wide support from Trust Center in Microsoft Office and the Visual Studio Tools for Office runtime, which helps resolve the security issues common to VBA code. There are many disadvantages to the VBA security model. An abundant number of viruses are easily developed using VBA macros. To run VBA macros safely, you have to set the security to high on the user machine, and digitally sign the code. More importantly, these operations need to be performed manually by the user. In VSTO 3.0, the Security Model has been changed. VSTO builds the security policy that is required to run and debug your solution on your computer every time that you build a project. The Assemblies are signed before publishing—this is done by Visual Studio 2008. Preferably, you obtain a certificate from a globally-acknowledged Certificate Authority or from an internal Certificate Authority, if the solution is only for an internal solution, and sign the manifests using the signing properties page in Visual Studio. Later, you publish the solution to its appropriate location.

Maintainability

VSTO solutions developed for an Office system are easier to maintain. Updating the deployed solutions, changing the code, and updating a single assembly will help more resources doing the same thing in multiple copies of the same documents. All of the code will reside inside the assembly—a partially-compiled code library that contains the logical unit of code inside it as a single dynamic link library ( .dll) file. With macros, the script resided inside the Office documents. Whenever you wanted to update the code, you had to modify every single document that contained it. With VSTO 3.0, managing application-level add-ins can be done by simply changing the code and updating the single assembly, instead of doing the same thing for multiple copies of the same document.

 

What's new in VSTO 3.0?


VSTO 3.0 is loaded with a wide variety of new features, and reloaded with enhancements of some of the key existing features. VSTO 3.0's new features target Microsoft Office 2007 (Office 12) tools with new functionalities and enhanced existing features. Let's list some of the key new features that are available in VSTO 3.0 that improve Office solution development work:

  • Document-level customizations: Document-level customizations are customized solutions that reside in a single document. Document-level customization using VSTO is one of the key features added in this new version of VSTO. VSTO supports document-level solutions for Microsoft Office Word, Microsoft Office Excel, and Microsoft Office InfoPath.

  • Application level add-ins: Application level add-ins are created as a managed code assembly using VSTO that will be loaded when the relevant Microsoft Office application is launched. VSTO 3.0 provides access to .NET objects and controls that you can program directly.

  • Visual Designers for Ribbons: Ribbons are the new way of organizing related commands. Visually, they appear as controls. Visual Designer provides advanced tools and supports developers in creating and designing custom Ribbons more easily.

  • Task Panes: The Task Pane helps users to access information quickly and more conveniently. Task Panes can be shown or hidden in the Office application user interface depending on the user's preference.

  • Form regions: Form regions are new ways to customize the user interface of the standard Microsoft Office Outlook 2007. For instance, VSTO 3.0 provides a Windows Forms-based design and development environment, in Visual Studio 2008. This allows Office developers to design and code the new Outlook form regions in single development environment and brings most of the Windows Forms to the hosting environment of Outlook.

  • Workflow support: VSTO provides visual designer support for developers to create Workflows using Visual Studio 2008. A Wizard option is used to create Workflows and directly assign these to the deployment location.

  • SharePoint support: New objects in VSTO help developers to program in Office applications for SharePoint. You can extend your Office client applications using VSTO and integrate them with a SharePoint Portal into an enterprise solution such as Customer Relationship Management, Supply Chain Management, and other similar applications.

  • Deployment using ClickOnce: New for VSTO 3, ClickOnce deployment technology allows Windows-based applications to be deployed and run with minimal user interaction. The security zone will limit the permissions and actions for applications that are deployed using ClickOnce technology.

  • Word content controls: Content controls are containers within which specific types of content, such as dates, lists, pictures, or text, can be placed.

  • Rich user interface controls: Office solutions can be built with rich and easy-to-access user interfaces. For instance, you can create an actions pane with windows controls, which has data interaction with other data sources in the actions pane.

  • Support for other Office applications: There is even a complex object model for Visio, which is somewhat different from the other Office applications, and can be challenging to understand. In Visio, each shape is represented as an object that you drag-and-drop onto the page from stencils. Understanding and manipulating these objects is the key to creating Visio applications solution.

Note

Stencils are collections of Visio shapes that you can add to your drawings, and that are contained in a Visio file.

 

VSTO architecture


Architecture is the essential association of a system that comes to life in its components, their associations to each other and to the environment, and the main beliefs guiding its design, and evolution. VSTO applications are composed of Office applications and .NET assemblies.

  • Office applications: VSTO exposes objects that make it easier to program Office applications. These include objects that enhance the application and process the data that the application uses. One of the most important points to understand is that the Word and Excel editors provide a view of a Word or Excel document. Using these editors, you can edit and format the document as though you were working directly in an Office application.

  • .NET assemblies: These contain Intermediate Language(IL) code. Metadata, which is binary information describing your program, is stored in memory and is part of a .NET assembly. In addition to metadata information, assemblies also have a special file called a Manifest. The Manifest contains information about the current version of the assembly.

The core components of VSTO Architecture are document-level customizations, application-level add-ins, and a Data Model at the document level. The new architecture of VSTO allows Office applications to be written and run with macros embedded inside the application.

The preceding image represents the Microsoft Office 2007 Solution Logical Architecture. VSTO enables Office developers to build document-level customizations for InfoPath, Word, and Excel documents, whereas for Outlook, PowerPoint, and Visio, there are no document-level customization features supported by VSTO.

VSTO provides very good support for object-oriented programming, a feature lacking in VBA scripting. VSTO provides full support for the C# programming language, allowing the implementation of object-oriented programming in Office solutions. Object-oriented programming is a kind of programming that relates coding blocks to objects. In other words, object-oriented programming is a software programming approach in which the structures of a program are based on objects' interaction with other objects, in order to perform or execute tasks.VSTO has several objects to work with in order to create applications using VSTO 3.0.

The architectural design of VSTO helps the Office developer in programming separately for application and data. The VSTO architecture design provides enhanced support for developing application-level solutions, and it exposes various objects that will make it easier for Office developers to program for Office applications. The most important point that you have to understand is that Word and Excel are the editors for the data they represent. Using these editors, you can edit and format the visually-displayed data. VSTO exposes a wide range of objects for enhancing the application and for processing the data inside the application for all of the Office applications that support it. Developing application level and document-level solutions is another architectural advancement in VSTO.

Development approaches

The types of solutions that we can create by using VSTO 3.0 fall into two categories, which we will use throughout this book—document-level solutions, and application-level solutions. Let's discuss each briefly.

Document-oriented approach

The document-oriented approach is designed specifically to get to the core of a Word or Excel document and include information that the document wasn't originally designed to support. VSTO 3.0 supports the creation of document-oriented approaches for InfoPath, Word, and Excel. Essentially, document-oriented approaches provide a document pointing to very specific tasks. An example of a document-oriented approach would be where uniform template kind of documents are managed inside a team or company without affecting the application of the document that they reside in.

A point to note is that the document-oriented approach will apply to most, but not all, Office 2007 applications.

Application-oriented approach

VSTO 3.0 is capable of creating application-oriented approaches for all of the applications in the Office 2007 suite. You can create and implement add-ins that add a wide range of functionalities and features to your Office application. The application-oriented approach replaces VBA, and adds new features such as add-ins for 2007 Microsoft Office applications that support enterprise solution development using VSTO. Furthermore, the approach supports the six applications in the 2007 Microsoft Office system, along with the tools and enhanced application programming interfaces(APIs) for customizing the Ribbon UI and creating custom task panes and add-ins. An API is a set of declarations of the functions or procedures provided in order to support requests made by computer programs.

 

VSTO development and deployment


The VSTO system 3.0 Runtime, which is the primary requirement to run the Office 2007 solutions, is built on VSTO. More importantly, the VSTO 3.0 is built into the Visual Studio 2008 installer. Service pack 1 for Visual Studio 2008 is available for users, which will improve the Visual Studio performance, and fix unknown bugs. The following VSTO related bug that used to load VSTO-derived Outlook Addins, was also fixed in Service Pack 1 — AddinLoader.DLL, is not signed. This DLL MUST be signed so as to enable Outlook to load any add-in developed under VSTO 2005, when user sets Macro security to High, and Trust installed addins... is NOT selected.

 

Creating Office applications through VSTO


VSTO is included in the Visual Studio 2008 release, which is a set of related libraries and designers for developing applications, along with add-ins for Microsoft Office 2003 and 2007. Microsoft has bundled VSTO 3.0 with Visual Studio 2008 for the first time, which also represents a considerable step forward in the development environment. Previously, developers had to install Visual Studio and VSTO separately in order to build a development environment. Also, it was necessary to perform manual configuration in order to enable debugging for Office solutions.

Microsoft Office remains the best Office application when it comes to automating processes, as well as for using different types of data sources for presenting data to the user. In VSTO 3.0, Microsoft Office tools have become more powerful for presenting data from business applications because Microsoft has made the Office development environment more developer-friendly by creating a new development environment that helps developers to build solutions that function inside Office applications. Thus, Microsoft Office developers are able to easily create solutions that can do more for their business, while reducing costs by reusing existing functionality available in the Office applications.

VSTO can even integrate with your existing ERP system, and increase your enterprise's growth. One leading logistics company has integrated its existing enterprise application with Microsoft Office application using Visual Studio Tools for Office. You can extend your Office client applications by using VSTO and integrate VSTO with the SharePoint Portal to provide enterprise solutions such as Office Business Applications, including Customer Relationship Management, Supply Chain Management, and many others.

The preceding image represents Office 2007 and its extensibility using VSTO 3.0. All of the extensible features of VSTO 3.0 are not common to all of the Office 2007 applications. For example, application-level add-ins are not supported by Access 2007, and custom task panes are not supported by Visio 2007. VSTO documents contain a deployment manifest. The deployment manifest is an XML file that contains a description of the ClickOnce deployment, including the identification of and other information about the current ClickOnce application version that is to be deployed. The location of the VSTO document assembly will be available inside the document's deployment manifest. You can programmatically manipulate the deployment manifest of a document.

VSTO development environment

VSTO 3.0 is not a separate installation package for Visual Studio 2008. VSTO 3.0 reduces the development installation effort for Office developers. While installing Visual Studio 2008, VSTO 3.0 is installed along with the other frameworks and needed components.

Note

You must install the Microsoft .NET Framework 3.5 redistributable package before installing the VSTO 3.0 Runtime. Developing and running Office customizations built with VSTO 3.0 requires the latest version of Microsoft Office 2007.

Package

The VSTO Runtime is installed when installing the Microsoft VSTO 3.0 redistributable package, which is essential for developing and deploying Office solutions using VSTO 3.0. A VSTO 3.0 redistributable package is the framework that brings the power and productivity of Visual Studio 2008 and the .NET framework to business solutions built on the Microsoft Office 2007 application.

The preceding image explains the version history of VSTO, highlighting some of the key differences between the versions. The current release of VSTO supports only the programming languages VB.NET and C#. We can expect other programming languages support in the next version of VSTO.

 

Visual Studio integration


VSTO 3.0 provides a visual representation of Office applications inside the Visual Studio, in order to easily create a customized user interface. VSTO 3.0 is well integrated with Visual Studio 2008, which provides the integrity for Office developers to develop and deploy Microsoft Office solutions for Microsoft Office tools. Visual Studio 2008 enables developers to build scalable Office business applications, influence key Office UI features, support workflow, and create easier deployments. Office development is a part of Visual Studio 2008 Professional and later versions, which focuses mainly on the developers' compatibility and maintainability assurances.

Let's take a look at a typical VSTO project template for an Office 2007 application in Visual Studio 2008.

In the preceding image, you can see the VSTO project templates for Office 2007 applications in Visual Studio 2008. Visual Studio 2008 has been packed with all of the VSTO 3.0 components needed to build an Office solution using VSTO. When installing Visual Studio 2008, all of the related installations, including project templates for VSTO 3.0, Office development references, and others, have been installed and fully-integrated into the new Visual Studio 2008 development environment.

Creating VSTO solutions

Visual Studio 2008 is very fast, collaborative, and flexible in developing and delivering a wave of innovative new Microsoft technologies, including enhanced language and data features. C# and VB.NET programming supported in Office 2007 is one of the enhanced language features, and easy data interaction with other data sources, such as Microsoft SQL server, is one of the data features. These features ensure that developers can rapidly create connected applications, deliver next generation software practices, and overcome application software development challenges.

The preceding image represents the development environment of the Office solution. In this figure, the client represents the development environment machine; the VSTO 3.0 inside Visual Studio 2008 represents the VSTO integrated Visual Studio; Office 2007 Client tools are the Office applications, including Word, Excel, InfoPath, and others, that should be installed in the client machine for development.

The development environment using Visual Studio 2008 is capable of creating application-level, data-centric solutions with VSTO 3.0. The data-centric solutions are the functionalities that are siginificantly focused on data manipulation and data storage.

The Visual Studio 2008 development environment makes it possible to develop solutions with great design-time and runtime support for key Office 2007 System features, such as the Ribbon, Custom Task Panes, document-level solutions, Outlook forms regions, and so on.

The Ribbon is a new way of representing menu items in the Office application. In the new development environment, you have a visual designer within which you can drag-and-drop controls inside the Ribbon, and design your custom Ribbon menus easily. Even for a data-related operation such as creating data connections, you have a data connection wizard for easy creation of a data connection.

Let's take a look at how the Office project solution looks, once it's been created in Visual Studio 2008. For example, we'll load a Word 2007 document solution created with Visual Studio 2008 and VSTO, using project templates available in the development environment:

The preceding image represents how the Office project solution for Word 2007 has been created in Visual Studio 2008. You can see all of the references listed as System.AddIn, System.Core, and so on. These are loaded automatically as a part of the project template. This provides the developer with easy-to-start programming by eliminating the manual process of adding references and validating the solution.

Office developers can integrate business data into documents by using XML-based data/view separation and programmability. For example, in InfoPath, you can easily integrate business data with the InfoPath forms, and you can program the data of the InfoPath, storing it as a separate file in XML format. You can also present the data in different views, depending on how the user wants to see it, in the user interface. You can develop solutions using the combined Outlook object model.

Viewing IDE Windows

Visual Studio is a fabulous Microsoft product designed especially for development activities. It is one of the most widely-used development tools among developers across the globe. It is built on an IDE, and enables developers to build different types of applications using Microsoft technologies. IDE is a software application for developing new software programs and applications that provides broad facilities to programmers for software development.

In general, IDE consists of a source code editor, compilers, and debuggers. Most readers will be familiar with the Visual Studio IDE. Visual Studio 2008 has an appearance similar to previous IDEs, but with more enhancements. By default, Microsoft Visual Studio IDE will provide you with IntelliSense, debugging, compilers for .NET programming, access to control controls, and the ability to build solutions. The latest enhancements such as visual designer for Ribbon, drag-and-drop controls, and enhanced debugging for Office applications will reduce the development time and increase the productivity of developers.

The in-built VSTO object model is designed to support .NET. And it's also simple! Many common functions are packaged and well-integrated. In the new version, tools such as Word, Excel, and InfoPath's target windows, are integrated directly into the IDE interface. This helps Office developers to build solutions without needing an advanced knowledge of the underlying object model. VSTO also has visual designers for Word 2007 and Excel 2007 that are in the Visual Studio IDE.

In the preceding image, we can see how the visual designer for Word 2007 appears in Visual Studio 2008. In this environment, you have the drag-and-drop functionality and other easy-to-design layouts for the use of an Office developer. Visual Studio 2008 brings the visual designer for other Office tools such as Excel and Infopath into the IDE. In a similar way, the Visual Studio 2008 IDE brings the visual Ribbon designer for Office tools into the interface. The Ribbon designer allows an Office developer to visually design an Office Ribbon (officially called the Office Fluent user interface) using the well-known drag-and-drop interface, and interact with the Ribbon using standard .NET code.

The preceding image shows the visual designer for the Ribbon in Office solution development, which simplifies the Ribbon development process for Office developers by providing drag-and-drop controls and easy access to resources. Similarly, Visual Studio 2008 simplifies and speeds up the development process of the actions pane, document-specific Task Panes, creating application-specific custom Task Panes, and Outlook Form Region Designer.

Debugging

Debugging is one of the most important tasks in software development, and a task that all developers will have run into many times in their programming lives. Developers have several debugging alternatives available for debugging their .NET applications that have DLL files in the Visual Studio IDE.

Visual Studio 2008 provides a strong set of build and debugging tools for Office solution development using VSTO 3.0. This is a big improvement over VSTO 2.0, which did not provide preconfigured debugging options. During configuration of the build, developers can select the components that they want to build, and exclude those that they want to avoid for the current build. A developer has the flexibility to build configurations for solutions as well as projects.

 

What can we expect in the next version?


The following points list some of the features we can expect in the next version of VSTO, based on the author's analysis and experiences as a VSTO developer:

  • Presently, VSTO 3.0 supports VB.NET and C# for Office solution development. In future releases of VSTO, we can expect support for other languages such as C++, which will help C++ developers to build VSTO solutions.

  • VSTO 3.0 smart tags are limited to document-level solutions in Office applications. They cannot be used in application-level solutions. Therefore we can expect Microsoft to add this feature in a future version of VSTO.

  • Building workflow activities inside of Office applications by using VSTO and a Visual Studio environment is another feature that we can expect in the next release. Interoperability of data and applications is at the core of windows workflow, and progress in VSTO helps us to reorganize workflow-oriented development.

  • Using VSTO to create document-level custom Tasks Panes for Visio applications should also be added in a future version. This will be useful for managing custom shapes for Visio users.

 

Summary


Microsoft has rebuilt the Office development framework, VSTO, with a wide variety of features, and has also enhanced most of the existing features. In this chapter, we went through the features and functionalities of VSTO 3.0. You have seen what VSTO is about and how it can be used for Office 2007 application customization. You have learned how VSTO is integrated with Visual Studio 2008, and how easy it is for a developer to create a solution using Visual Studio 2008. You have also seen some of its key features such as custom Task panes, Ribbons, Add-ins and document-level customization, and so on, and how these are helpful for Office developers. In this chapter you have also seen the architecture of VSTO and IDE for VSTO development, and have learned the enhanced debugging features for VSTO in Visual Studio IDE. You have learned the concept of object-oriented support in VSTO Office solution development, and have also seen the C# programming language and .NET framework technology platform support for Office development.

About the Author

  • Vivek 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.

    Browse publications by this author

Latest Reviews

(1 reviews total)
I received what I ordered, but it was a week late in arriving.
Book Title
Access this book, plus 7,500 other titles for FREE
Access now