VS2010: Office Development

 By Tim Anderson

Building applications for Microsoft Office and SharePoint.

HardCopy Issue: 52 | Found In: Visual Studio 2010 | Published: 19/05/2011 | Last Revision: 19/05/2011

Two things have shaped the Microsoft Office development platform in recent years. One is the growing popularity of SharePoint, the document and collaboration server, which fits well with the demand for Internet-based content management and workflow solutions. The other is the evolution of Visual Studio Tools for Office (VSTO), which lets you extend Office with .NET code. These both changed substantially with the advent of Office 2010, SharePoint 2010 and Visual Studio 2010.

SharePoint development

The big news is that developing and debugging SharePoint applications has become less painful now that SharePoint has become a first-class project type within Visual Studio. SharePoint servers are also now available in the Server Explorer, letting you drill down through all the available elements and inspect their properties. That said, there is still some effort involved in setting up a SharePoint 2010 development machine. You need 64-bit Windows, and you need to install SharePoint 2010 on the development box, where it will take over port 80, as well as the SharePoint 2010 SDK. The new tools target SharePoint 2010 only, with the exception of Sequential and State Machine Workflow projects which come in both 2010 and 2007 flavours. SharePoint 2010 is built on ASP.NET. A SharePoint Application Page is a custom ASP.NET page, and a Web Part is a container for an ASP.NET User Control. This means that developers get the features of ASP.NET combined with the rich SharePoint document and collaboration APIs. Visual Studio 2010 offers several SharePoint project types. Web Parts let you modify the appearance and behaviour of SharePoint pages, or give end users tools to do so. Sequential or State Machine workflows let you design a workflow, with activities, states and events, which is applied to items in one or more SharePoint lists. A common example is a document approval process.

Ribbon Designer screenshot
The visual Ribbon Designer is new to Visual Studio 2010.

The Business Data Connectivity Model project is a standardised technique for integrating SharePoint with external data such as contacts, knowledgebase items, sales records in a relational database, or other data accessed through Web services. Business Connectivity Services surfaces this data in SharePoint lists and Web parts, or directly in Office applications. An Event Receiver project lets you write code triggered by SharePoint events, such as when a document is added or changed. The wizard hooks you up to the events and gives you event handlers for adding custom code. Visual Studio automatically deploys your projects to the local development site for testing. When you are ready to deploy for real, you can use the Package option on the Build menu to create a SharePoint package file. You can then deploy this to another SharePoint server using administration tools. Overall, it is now easier for developers to take advantage of SharePoint for customising intranet and Internet sites, or building applications that exploit SharePoint’s extensive features.

Developing with Office

It was back in Office 2003 days that Visual Studio Tools for Office (VSTO) brought the power and performance of .NET programming to Microsoft’s familiar productivity suite. Coding in .NET rather than the old Visual Basic for Applications (VBA) makes it easier to integrate with other applications and data sources, and means all the features of Visual Studio are available. That said, there were a few snags with VSTO, especially for C# developers. Lack of support for optional parameters meant peppering the code with ‘ref missing’ or its equivalent. Another issue was that solutions were complex to deploy with dependency on the VSTO runtime, the Office Primary Interop Assemblies, and to specific versions of Office.

SharePoint project type screenshot
Choosing a SharePoint project type.

These issues have not completely gone away, but Office Development with Visual Studio 2010 and .NET 4.0 is less hassle than before. The dynamic features in C# 4.0 and support for optional and named parameters are a great fit with the Office COM API. You can now embed interop types into your VSTO assemblies, giving it better resilience to changes in Office or future versions of VSTO. Furthermore you can target both Office 2007 and Office 2010 using Visual Studio 2010 and .NET 4.0, provided that you install the new VSTO runtime and keep to features that are common to both. A key new feature in Visual Studio is a visual designer for the Office Ribbon. Although some users still hanker after the old menus, the ribbon is great for developers since it offers a richer surface for user interface controls, including buttons, checkboxes, dropdown lists, image galleries and edit boxes. You can also modify what is on the ribbon in response to events, making it context-sensitive or updated from external data. There is also a 64-bit version of VSTO so that you can take advantage of 64-bit Windows and Office.

Share and Bookmark  

Comments

Be the first to comment about this article...

Leave a comment

You must login to place comments.

Skin Border Image

Related Links

Skin Border Image