On CBS.com: Watch all U2's performances and skits

Build Office-based apps with a Visual Studio add-in

Tags: Microsoft development tools, .NET, Middleware, Tony Patton, Microsoft Office, VSTO, Microsoft Visual Studio, Microsoft .NET, Microsoft Corp., .NET Newsletter

  • Save
  • Print
  • Recommend
  • 0

Takeaway: Read this overview of Visual Studio Tools for Office (VSTO), a Visual Studio 2005 add-on that promotes the building of Office-based applications. We also provide you with VSTO deployment and security strategies.

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 Outlook 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.

Features

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.

Security


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.

Deployment

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 evidence.

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 solutions.

Old meets new


One surprise is VSTO's reliance on Component 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 client.

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.

  • Save
  • Print
  • Recommend
  • 0

Print/View all Posts Comments on this article

Any advantages of VSTO instead of VB6 for Outlook add-in? MattiasW | 02/22/06
You can and you can't? sbsinc | 02/22/06
VSTO 2003 vs 2005... 2003 doesn't work non-professional installs haasey@... | 02/23/06

What do you think?

White Papers, Webcasts, and Downloads

Article Categories

Security
Security Solutions, IT Locksmith
Networking and Communications
E-mail Administration NetNote, Cisco Routers and Switches
CIO and IT Management
Project Management, CIO Issues, Strategies that Scale
Desktops, Laptops & OS
Windows 2000 Professional, Microsoft Word, Microsoft Excel, Microsoft Access, Windows XP,
Data Management
Oracle, SQL Server
Servers
Windows NT, Linux NetNote, Windows Server 2003
Career Development
Geek Trivia
Software/Web Development
Web Development Zone, Visual Basic, .NET

Meet Doc

advertisement
Click Here