getting started with vsto

31
Copyright © by Application Developers Training Company Getting Started with Getting Started with VSTO VSTO

Upload: learnnowonline

Post on 24-May-2015

1.161 views

Category:

Technology


2 download

DESCRIPTION

Find out what kinds of solutions you can build using Microsoft Visual Studio 2005 Tools for the 2007 Microsoft Office System.

TRANSCRIPT

Page 1: Getting Started with VSTO

Copyright © by Application Developers Training Company

Getting Started with VSTOGetting Started with VSTO

Page 2: Getting Started with VSTO

Copyright © by Application Developers Training Company

ObjectivesObjectives• Find out what kinds of solutions you can

build using Microsoft Visual Studio 2005 Tools for the 2007 Microsoft Office System

• See how to create a simple Visual Studio Tools (VSTO) for Office solution

• Investigate the components that make up a VSTO solution

• Learn some basic concepts of writing managed code solutions using Visual Studio and the .NET Framework

Page 3: Getting Started with VSTO

Copyright © by Application Developers Training Company

AgendaAgenda• Building Solutions with Microsoft

Office System• Creating Your First VSTO 2005 SE Project• Introducing Managed Code

Page 4: Getting Started with VSTO

Copyright © by Application Developers Training Company

Building Solutions with Microsoft Building Solutions with Microsoft Office SystemOffice System• VBA has made it possible to create

solutions that build on what Office provides Powerful but … Dated

• Visual Studio Tools for Office Document-based solutions for Excel 2003 and

Word 2003 Add-in solutions for most Office 2003 and Office

2007 products Ability to use VB.NET, C#, and the .NET

Framework

Page 5: Getting Started with VSTO

Copyright © by Application Developers Training Company

What Can You Do with VSTO?What Can You Do with VSTO?Visual Studio 2005

Tools for the Microsoft Office

System

(VSTO 2005) Visual Studio 2005 Tools for the 2007

Microsoft Office System

(VSTO 2005 SE)Visual Studio 2005 Professional

(VS2005 Pro)

Visual Studio 2005 Team System

(VS2005 Team)

Document-level: Excel 2003, Word 2003Application-level: Outlook 2003

Document-level: Excel 2003, Word 2003Application-level: Outlook 2003

No built-in VSTO functionality

Application-level solutions: 2003 and 2007InfoPath 2007 Forms

Page 6: Getting Started with VSTO

Copyright © by Application Developers Training Company

Starting with a Full Version of Starting with a Full Version of VSTOVSTO• VSTO 2005 or Team System• Document-level solutions

Word 2003 Professional Excel 2003 Professional InfoPath 2007

• Application-level solutions (add-ins) Word 2003/2007 Excel 2003/2007 InfoPath 2007

Outlook 2003/2007 PowerPoint 2003/2007 Visio 2007

Page 7: Getting Started with VSTO

Copyright © by Application Developers Training Company

Starting with Visual Studio 2005 Starting with Visual Studio 2005 ProfessionalProfessional• Document-level solutions: None• Application-level solutions (add-ins)

Word 2003/2007 Excel 2003/2007 InfoPath 2007 Outlook 2003/2007 PowerPoint 2003/2007 Visio 2007

Page 8: Getting Started with VSTO

Copyright © by Application Developers Training Company

What’s included in VSTO 2005 + What’s included in VSTO 2005 + VSTO 2005 SEVSTO 2005 SE• VS 2005 IDE• Templates for the solution types mentioned• VB and C# programming languages• Designers for WinForms, WebForms,

database and data access, and classes• Support for XML and XSLT• SQL Server 2005 Developer Edition• Deployment Tools• Access 2003 Developer Extensions and

Runtime

Page 9: Getting Started with VSTO

Copyright © by Application Developers Training Company

Choosing a Development Choosing a Development LanguageLanguage• You can use either Visual Basic or C#• Personal preference, but…

If you use C# there are issues surrounding working with the Office object models that you need to know about

If you use VB you should at least know how to read C# so you can read examples

• In this course, we'll use mostly VB

Page 10: Getting Started with VSTO

Copyright © by Application Developers Training Company

AgendaAgenda• Building Solutions with Microsoft Office

System• Creating Your First VSTO 2005 SE

Project• Introducing Managed Code

Page 11: Getting Started with VSTO

Copyright © by Application Developers Training Company

VSTO 2005 SE PrerequisitesVSTO 2005 SE Prerequisites• For Office 2003 solutions, you need one

of: Microsoft Office 2003, Professional Edition Standalone version of Word 2003 or Excel

2003

• For Office 2007 solutions, any edition of Office 2007 will work

• Even though you can run Office 2003 and Office 2007 side-by-side, you can only develop VSTO 2005 SE solutions for one or the other

Page 12: Getting Started with VSTO

Copyright © by Application Developers Training Company

VSTO 2005 SE PrerequisitesVSTO 2005 SE Prerequisites• In any case, be sure .NET Programmability

Support is installed with the product .NET Programmability Support = Primary

Interop Assemblies (PIAs) PIAs allow communication between managed

code (.NET) and unmanaged code (COM) In Office 2003, do a Custom install In Office 2007, PIAs are installed by default

• PIAs can also be downloaded and installed separately, or as part of a custom setup for your solution

Page 13: Getting Started with VSTO

Copyright © by Application Developers Training Company

Office Edition Prerequisites: User's Office Edition Prerequisites: User's ComputerComputer

• Application-level solutions written for Office 2003 will run on any edition of Office 2003

• Document-level and application-level solutions written for Office 2003 will run on any edition of Office 2007

Page 14: Getting Started with VSTO

Copyright © by Application Developers Training Company

Creating a New Document-Level Creating a New Document-Level SolutionSolution

• Excel 2003 and Word 2003 only• Either documents (.doc or .xls) or

templates (.dot or .xlt)• Document-level solutions will work in

Office 2007, but you need to develop them in Office 2003

Page 15: Getting Started with VSTO

Copyright © by Application Developers Training Company

The DocumentThe Document• VSTO 2005 SE adds an ActiveX control

Runtime Storage Control Embedded application manifest + cached data

sets

• Custom property named _AssemblyName Always has a value of * (an asterisk)

• Custom property named _AssemblyLocation GUID Identifies the Runtime Storage Control

Page 16: Getting Started with VSTO

Copyright © by Application Developers Training Company

The AssemblyThe Assembly• Code runs in response to events, like

Startup and Shutdown• If you open a doc with _AssemblyName =

* VSTO loader starts the VSTO 2005 SE runtime

(VSTOR) VSTOR checks the Code Access Security policy VSTOR uses the embedded application

manifest to find the assembly Your code runs

Page 17: Getting Started with VSTO

Copyright © by Application Developers Training Company

Creating a New Application-Level Creating a New Application-Level SolutionSolution

• Template adds two projects: Project for your solution containing a

ThisAddIn class Project for setup so you can install on another

computer

• ThisAddIn members include Application points to the host application Office 2007: CustomTaskPanes allows you to

add task panes to the host app's UI

Page 18: Getting Started with VSTO

Copyright © by Application Developers Training Company

Loading an Add-InLoading an Add-In• Office product checks registry for add-ins to load

Registry settings point to application manifest Application manifest points to deployment manifest

• VSTO add-in loader (AddInLoader.dll) starts• AddInLoader starts VSTOR• VSTOR

Reads application manifest Uses deployment manifest to see if newer version is

available Creates application domain Checks Code Access Security policy

• Your code runs

Page 19: Getting Started with VSTO

Copyright © by Application Developers Training Company

AgendaAgenda• Building Solutions with Microsoft Office

System• Creating Your First VSTO 2005 SE Project• Introducing Managed Code

Page 20: Getting Started with VSTO

Copyright © by Application Developers Training Company

Introducing Managed CodeIntroducing Managed Code• Whether VBA or VSTO 2005 SE, you still need

to perform the same tasks Provide a UI Translate host app's features into code Work with variables, conditional logic, looping,

specialized tasks

• If you're coming from VBA Forms are entirely new Most VBA code will run with little modification, but… For many tasks, you can write more robust, more

efficient, and shorter code by using .NET Framework

Page 21: Getting Started with VSTO

Copyright © by Application Developers Training Company

.NET Framework Basics.NET Framework Basics• Library of types that integrate with .NET's

Common Language Runtime• Provides members for everything from

data types to sending e-mail• Consistent architecture, so it's not as hard

to learn as its size might indicate

Page 22: Getting Started with VSTO

Copyright © by Application Developers Training Company

.NET Framework Examples.NET Framework Examples• Working with the String Data Type• Getting File System Information• Exception Handling• Building Your Own Classes• Working with Windows Forms

Page 23: Getting Started with VSTO

Copyright © by Application Developers Training Company

.NET Data Types.NET Data Types• .NET Framework provides data types as

members of the System namespace System.Boolean System.DateTime System.Double System.String …etc.

• You can use familiar aliases, without the System-dot

Page 24: Getting Started with VSTO

Copyright © by Application Developers Training Company

Working with StringsWorking with Strings• .NET Framework data types provide

Variable storage Shared members

If result = String.Empty Then Console.WriteLine("No text entered")End If

Console.WriteLine( _ String.Format("You typed {0}", result)

Page 25: Getting Started with VSTO

Copyright © by Application Developers Training Company

Working with StringsWorking with Strings• System.String also provides string

methods like the string functions in VBA .Length .ToUpper/.ToLower .Contains .IndexOf .Replace

• In Visual Basic, you can still use the VBA functions

Page 26: Getting Started with VSTO

Copyright © by Application Developers Training Company

Getting File System InformationGetting File System Information• FileSystem functions are available in VBA,

but no fun to use• .NET Framework's System.IO namespace

is much easier to work with Create, copy, move, delete folders or files Read/write files Get/set file attributes Parse paths and file name strings

Page 27: Getting Started with VSTO

Copyright © by Application Developers Training Company

Exception HandlingException Handling• You "catch" errors with a Try…Catch block

Try ' Code that might fail goes hereCatch ' Code that responds to error goes hereEnd Try

• Use instance of the System.Exception class to determine what happened

Try ' Code that might fail goes hereCatch ex As Exception ' Can use Exception members to determine errorEnd Try

Page 28: Getting Started with VSTO

Copyright © by Application Developers Training Company

Building Your Own ClassesBuilding Your Own Classes• Your classes

Inherit from System.Object Can inherit from other .NET Framework

classes, or your own Can provide multiple constructors, fields,

properties, and methods

Page 29: Getting Started with VSTO

Copyright © by Application Developers Training Company

Working with Windows FormsWorking with Windows Forms• WinForms are classes that inherit from

System.Windows.Forms.Form• Many more controls than userforms• Support data binding to

Database objects Web services Objects defined as classes in your solution

o Custom classeso My.Settings class included in all VB projects

Page 30: Getting Started with VSTO

Copyright © by Application Developers Training Company

Using a Windows Form in Your User Using a Windows Form in Your User InterfaceInterface

• Instantiate with the New keyword• Use Show method (non-modal) or

ShowDialog method (modal)

Dim frm As New ExceptionsFormfrm.Show()

Page 31: Getting Started with VSTO

Copyright © by Application Developers Training Company

Binding to the My NamespaceBinding to the My Namespace• Example: Add a data bound form to the

add-in created earlier• Data is a setting in the My namespace

Store last time form was loaded Display that time the next time form is loaded Show form when add-in starts up

• Not particularly useful, but you get to use… Data Source Configuration Wizard Form designer Data binding design tools