Microsoft’s share of the office productivity suite market is
no secret as Microsoft Office dominates the competition. For this reason, it is
often desirable to harness the power of the Office suite when developing custom
applications. After all, who wants to reinvent the wheel?

Previously, I have discussed how to work with individual
Office products like Word, Excel, and
via .NET; Microsoft offers an even more integrated platform with Visual Studio Tools
for Office (VSTO)
. In this column, I provide an overview of the product,
along with detailed examples of how to integrate VSTO with .NET applications.

Weekly .NET tips in your inbox

TechRepublic’s free .NET newsletter, delivered each Wednesday, contains useful tips and coding examples on topics such as Web services, ASP.NET, ADO.NET, and Visual Studio .NET.

Automatically sign up today!

What is VSTO?

VSTO is a Visual Studio 2005
add-on that promotes the building of .NET-based applications, which take
advantage of Microsoft Office functionality. It allows you to host custom
applications within the individual Office products, while taking advantage of
.NET features like a rich user interface development as well as separating code
from documents. Each product offers an extensive programming object model that
allows you to utilize your preferred language like C# or VB.NET.

VSTO, which works with Microsoft Office 2003, is a radical
departure from the old approach of using Visual Basic for Applications (VBA).
It provides three approaches to application development: Office automation,
Office add-in, and code-behind an Office document.


Once you install Visual Studio 2005, Microsoft Office 2003,
and VSTO, you are ready to build custom Office applications. VSTO includes
project templates that provide a starting point for application development.
You’ll find the templates under the VB.NET and C# projects folders in the
Office subfolder. (This includes templates for all Office products, as well as
Outlook add-ins.)

A powerful feature of VSTO is that the Word and Excel
application environments are integrated into Visual Studio, so you can easily
work with the features of each application within the IDE. Also, you may use
Windows Form controls in the applications, as well as host controls
for both Word and Excel. (The host controls are available via the Visual Studio
toolbox.) Other available features include SmartTags
and action panes within Office documents. The major area of development is
backend data integration, which includes ADO.NET programming and databinding.


It’s critical to keep security in mind when you’re
developing and deploying VSTO-based solutions; this includes accessing backend
data sources, directory access (if applications use existing documents), and
Component Access Security (CAS).

The VSTO security model is strict to prevent the spread of
macro viruses or worms. There are two things that must be trusted: the assembly
associated with the document and the location of the document.

The VSTO security model for assemblies says no assembly is
trusted by default. The security model for documents says only local machine documents
are trusted by default. The loading of a customized document checks both assembly
and document location trust in order to determine whether it is loaded.

Regardless of the assembly location, you must have a .NET security
policy in place to trust the assembly. This isn’t a problem as long as the
document resides locally on your computer.


Follow these steps to deploy a VSTO solution:

  1. Choose
    a deployment model (Windows Installer, Publish Wizard, etc.).
  2. Install
    the prerequisites on each user’s computer. This includes the .NET
    Framework, VSTO, Microsoft Office 2003 primary interop
    assemblies, and any other necessary components. (These prerequisites may
    be included in an installer package.)
  3. Prepare
    the solution to deploy.
  4. Copy
    the appropriate files to the deployment location. (If you’re working with
    Outlook, required registry entries will be necessary.)
  5. Grant
    trust to the solution’s assemblies. This is a critical step to ensuring
    appropriate application operation. You must grant the customization
    assembly FullTrust permissions. In addition, you
    must trust any referenced or satellite assemblies with the appropriate
    level of permissions. Evidence for the trust can consist of an assembly’s
    location, a strong name, a certificate, or a combination of these types of

You can find a more detailed description of the deployment
on MSDN. I also recommend checking out the VSTO Zone on OfficeZealot,
where developers expose a variety of issues concerning the deployment of VSTO

Old meets new

One surprise is VSTO’s reliance on
Object Model (COM)
. It amazes me that Microsoft Office development still
utilizes COM, especially since the .NET Framework has been around for years, and
Microsoft promotes it as the solution for all programming endeavors. However,
Office’s reliance on COM makes it easy to migrate
existing solutions when new Office versions are released or installed. We’ll
have to wait and see when Microsoft will migrate the
Office suite to full .NET programmability. For now, COM is still with us, so we
have to get used to it.

A world of possibilities

VSTO makes it easy to build Office-based applications. You
can develop Office product add-ons, automate Office objects, or simply develop
code to provide additional functionality in an Office document. This add-in
also allows you to utilize your .NET programming skills to manipulate Office.
Take advantage of VSTO to build powerful business applications for your next

Tony Patton began his professional career as an application developer earning Java, VB, Lotus, and XML certifications to bolster his knowledge.

Miss a column?

Check out the .NET Archive, and catch up on the most recent editions of Tony Patton’s column.