33.1. Choosing an Office Project Type

The types of applications you can create using VSTO under Visual Studio have come a long way with the latest version. You now have the ability to create add-in applications for almost every product in the Office suite. Furthermore, these solutions can either be attached to a single document, or be loaded every time that application is launched.

You can create a new Office application by selecting File New Project. Select your preferred language (Visual Basic or Visual C#), and then select the Office project category, as shown in Figure 33-1.

It is technically possible to create Office applications using .NET languages besides Visual Basic or Visual C#. However, you will lose the benefits of the project and item templates and designer support provided by Visual Studio. Though it might be a good academic exercise to try creating an Outlook add-in using IronRuby, it will also be a lot more work.

Visual Studio 2008 provides templates for both Office 2003 and Office 2007. The same projects can be created under both versions of Office, with the addition of SharePoint and InfoPath under Office 2007.

Figure 33.1. Figure 33-1

The project templates can be broadly categorized into four types of Office applications: document-level customizations, application-level add-ins, SharePoint workflows, and InfoPath forms.

33.1.1. Document-Level Customizations

A document-level customization is a solution that is based on a single document. To load the customization, an end user must open a specific document. Events in the document, such as loading the document or clicking buttons and menu items, can invoke event handler methods in the attached assembly. Document-level customizations can also be included with an Office template, which ensures that the customization is included when you create a new document from that template.

Visual Studio 2008 allows you to create document-level customizations for the following types of documents:

  • Microsoft Excel Workbook

  • Microsoft Excel Template

  • Microsoft Word Document

  • Microsoft Word Template

Using a document-level customization, you can modify the user interface of Word or Excel to provide a unique solution for your end users. For example, you can add new controls to the Office 2007 Ribbon or display a customized Actions Pane window.

Microsoft Word and Microsoft Excel also include a technology called smart tags, which enable developers to track the user's input and recognize when text in a specific format has been entered. Your solution can use this technology by providing feedback or even actions that the user could take in response to certain recognized terms, such as a phone number or address.

Visual Studio also provides a set of custom controls that are specific to Microsoft Word 2007. Called content controls, they allow you to do a number of useful things such as providing a rich user interface for entering data in the document or displaying data that is bound to those controls. You will see content controls in action later in this chapter.

33.1.2. Application-Level Add-In

Unlike a document-level customization, an application-level add-in is always loaded regardless of the document that is currently open. In fact, application-level add-ins will run even if the application is running with no documents open.

Previous versions of VSTO had significant limitations when it came to application-level add-ins. First, you could create add-ins only for Microsoft Outlook, and even then you could not customize much of the user interface.

Fortunately in Visual Studio 2008 such restrictions no longer exist, and you can create application-level add-ins for almost every product in the Microsoft Office suite, including Excel, InfoPath, Outlook, PowerPoint, Project, Visio, and Word. This applies equally to version 2003 and version 2007 of Office. You can create the same UI enhancements as you can with a document-level customization, such as adding new controls to the Office Ribbon.

You can also create a custom Task Pane as part of your add-in. Task Panes are very similar to the Action Panes that are available in document-level customization projects. However, custom Task Panes are associated with the application, not a specific document, and as such can be created only within an application-level add-in.

An Actions Pane, on the other hand, is a specific type of Task Pane that is customizable and is attached to a specific Word document or Excel workbook. You cannot create an Actions Pane in an application-level add-in.

Also new to Visual Studio 2008 is the ability to create custom Outlook form regions in Outlook add-in projects. Form regions are the screens that are displayed when an Outlook item is opened, such as a Contact or Appointment. You can either extend the existing form regions or create a completely custom Outlook form. Later in this chapter you walk through the creation of an Outlook 2007 add-in that includes a custom Outlook form region.

33.1.3. SharePoint Workflow

SharePoint workflows are used to define and control a process lifecycle for documents stored in a Microsoft SharePoint Server 2007 repository. Visual Studio 2008 provides support for two types of workflows: a sequential workflow and a state machine workflow.

A sequential workflow represents the workflow as a set of steps that are executed in order. For example, a document is submitted that generates an e-mail to an approver. The approver opens the document in SharePoint and either approves or rejects it. If approved, the document is published. If rejected, an e-mail is sent back to the submitter with the details of why it was rejected.

A state machine workflow represents the workflow as a set of states, transitions, and events. You define the start state for the workflow and it will transit to a new state when an event occurs. For example, you may have states such as Document Created and Document Published, and events that control the transition to these states such as Document Submitted and Document Approved.

When you first create a SharePoint workflow in Visual Studio 2008, it will launch the New Office SharePoint Workflow Wizard, which is used to select a SharePoint server and site for debugging and to define the debug configuration settings. Once the wizard is completed, you can use the Workflow Designer to design the SharePoint workflow schedule.

You can also use Visual Studio to design a form that gathers information from users at specific points in a workflow. These forms can be created as either ASP.NET web pages or InfoPath forms.

You cannot use the SharePoint workflow project templates in Visual Studio unless you are running an operating system that supports SharePoint Server, such as Windows Server 2003 or 2008. You cannot use a client operating system such as Windows Vista. You will also need to install SharePoint Server 2007 on that machine.

33.1.4. InfoPath Form Template

When Microsoft first released InfoPath, it was seen as an excellent option for enabling organizations to build forms easily without having to resort to writing code. Though it was indeed the answer for many (providing the capability to create complex form designs with a robust graphical user interface and easy connection to data sources, all bound up in XML), it was difficult to create a form that was backed by code.

With the release of Visual Studio 2005, Microsoft also released the InfoPath 2003 Toolkit for Visual Studio 2005 as an additional download. The Toolkit integrated with InfoPath 2003 SP1 to provide a managed code solution for creating and managing InfoPath forms that rely on program code to perform part of their functionality.

InfoPath 2007 has made it even easier to develop rich forms with the inclusion of a much cleaner managed-code object model. Forms with code written using this new object model work the same way regardless of whether you open them using the InfoPath-rich client or a web browser via Microsoft Office Forms Server 2007.

You must have InfoPath 2007 installed on your local computer in order to create InfoPath form templates using Visual Studio.

Visual Studio 2008 includes native support for InfoPath form templates, including a project template and designer support for customizing the layout and design of your InfoPath forms. You can either design a new template from scratch, or based on a set of predefined templates that use external resources, such as a SQL database or web service. Additionally, you can create a template part that can be inserted in multiple form templates.

Though it's not obvious from the available project templates, you can use Visual Studio 2008 to create new form templates that work with InfoPath 2003. To maintain backward compatibility, create a new form template, click Tools Form Options, and then in the Programming category click the Remove Code button. You will then be able to choose either C# (InfoPath 2003 Compatible) or Visual Basic (InfoPath 2003 Compatible) as the form template code language.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.59.198