Microsoft SharePoint 2010 Professional Developers Evaluation Guide

Similar documents
Microsoft SharePoint 2010 Professional Developer s Evaluation Guide

SharePoint Composites. Do-It-Yourself SharePoint solutions

Best of SharePoint Composites

CHAPTER 1: INTRODUCTION TO SHAREPOINT

Noramsoft Inc. Noramsoft Inc. SPT2O1O - Course Description. Developing Solutions with SharePoint Server 2010 SPT2010. Noramsoft Inc. Noramsoft Inc.

Programmabilty. Programmability in Microsoft Dynamics AX Microsoft Dynamics AX White Paper

Key Benefits of Microsoft Visual Studio 2008

Getting started with Microsoft SharePoint Server 2010

SQL Server 2005 Reporting Services (SSRS)

Windows Azure Pack Installation and Initial Configuration

Understanding SharePoint Development Choices

Implementing and Administering an Enterprise SharePoint Environment


SHAREPOINT 2010 DEVELOPMENT : IN THE CLOUD. Faraz Khan Senior Consultant RBA Consulting

Microsoft SharePoint Server 2010: What s New and What s Changed?

Authoring for System Center 2012 Operations Manager

Reporting Services. White Paper. Published: August 2007 Updated: July 2008

Deploying the Workspace Application for Microsoft SharePoint Online

Executive Summary WHO SHOULD READ THIS PAPER?

Deciding When to Deploy Microsoft Windows SharePoint Services and Microsoft Office SharePoint Portal Server White Paper

SharePoint Checklist and Resources

Enterprise Application Development in SharePoint 2010

Writers: Joanne Hodgins, Omri Bahat, Morgan Oslake, and Matt Hollingsworth

TeamCompanion Solution Overview. Visual Studio

MICROSOFT DYNAMICS CRM Roadmap. Release Preview Guide. Q Service Update. Updated: August, 2011

BizTalk Server Business Activity Monitoring. Microsoft Corporation Published: April Abstract

Lab Answer Key for Module 6: Configuring and Managing Windows SharePoint Services 3.0. Table of Contents Lab 1: Configuring and Managing WSS 3.

SharePoint 2010/2013 Course

Usage Analysis Tools in SharePoint Products and Technologies

David Chou. Architect Microsoft

SharePoint 2010 Performance and Capacity Planning Best Practices

Webmetrics Web Monitoring Getting Started Guide

GSA2013: The Great SharePoint Adventure 2013

"Charting the Course to Your Success!" MOC B Configuring and Administering Microsoft SharePoint Course Summary

Creating and Deploying Active Directory Rights Management Services Templates Step-by-Step Guide

Step-by-Step Guide for Microsoft Advanced Group Policy Management 4.0

Integrating Business Portal 3.0 with Microsoft Office SharePoint Portal Server 2003: A Natural Fit

Business Portal for Microsoft Dynamics GP. Project Time and Expense Administrator s Guide Release 10.0

FORMS & WORKFLOW SHAREPOINT Practical Discussion

SharePoint 2013 Syllabus

System Requirements for Microsoft Dynamics NAV 2013 R2

Overview of Active Directory Rights Management Services with Windows Server 2008 R2

SPT2013: Developing Solutions with. SharePoint DAYS AUDIENCE FORMAT COURSE DESCRIPTION STUDENT PREREQUISITES

Migrate from Exchange Public Folders to Business Productivity Online Standard Suite

A SharePoint Developer Introduction

Windows Embedded Security and Surveillance Solutions

How to Prepare for the Upgrade to Microsoft Dynamics CRM 2013 (On-premises)

Installing Windows Rights Management Services with Service Pack 2 Step-by- Step Guide

Microsoft Dynamics GP. econnect Installation and Administration Guide Release 9.0

SharePoint 2010

Microsoft Corporation. Status: Preliminary documentation

The Recipe for Sarbanes-Oxley Compliance using Microsoft s SharePoint 2010 platform

Designing and Developing Microsoft SharePoint Server 2010 Applications (MS10232)

ThirtySix Software WRITE ONCE. APPROVE ONCE. USE EVERYWHERE. SMARTDOCS SHAREPOINT CONFIGURATION GUIDE THIRTYSIX SOFTWARE

SharePoint Integration Framework Developers Cookbook

Sage CRM Connector Tool White Paper

Local Touch Global Reach. SharePoint.

One of the fundamental kinds of Web sites that SharePoint 2010 allows

Automating Business Processes Using SharePoint Designer

Professional SharePoint 2013 Development

Windows Server Virtualization An Overview

Customizing Remote Desktop Web Access by Using Windows SharePoint Services Stepby-Step

Connector for Microsoft Dynamics Configuration Guide for Microsoft Dynamics SL

Master Data Services. SQL Server 2012 Books Online

Course 10174B: Configuring and Administering Microsoft SharePoint 2010

Configuring and Administrating Microsoft SharePoint 2010 (10174) HK913S

SharePoint 2010 Developer Track

126 SW 148 th Street Suite C-100, #105 Seattle, WA Tel: Fax:

MOC 20488B: Developing Microsoft SharePoint Server 2013 Core Solutions

MicrosoftDynam ics GP TenantServices Installation and Adm inistration Guide

Pipeliner CRM Phaenomena Guide Sales Target Tracking Pipelinersales Inc.

Integrating SharePoint Sites within WebSphere Portal

Microsoft SQL Server Master Data Services Roadmap

Microsoft Dynamics GP. Workflow Installation Guide Release 10.0

ITMC 2079 MCTS Configuring and Administering Microsoft SharePoint 2010

Microsoft Enterprise Project Management 2010 Licensing Guide

11 ways to migrate Lotus Notes applications to SharePoint and Office 365

SOLARWINDS ORION. Patch Manager Evaluation Guide for ConfigMgr 2012

What is New Whitepaper. White Paper

IBM WebSphere ILOG Rules for.net

SAS IT Resource Management 3.2

Credit Card Processing

Developing Microsoft SharePoint Server 2013 Core Solutions

Designing and Developing Microsoft SharePoint Server 2010 Applications Course Outline

Pipeliner CRM Phaenomena Guide Sales Pipeline Management Pipelinersales Inc.

Myriad Technologies Training 5 Day Level 200 Introduction

Course 10174B: Configuring and Administering Microsoft SharePoint 2010

User's Guide. ControlPoint. Change Manager (Advanced Copy) SharePoint Migration. v. 4.0

Veeam Backup Enterprise Manager. Version 7.0

Configuring and Administering Microsoft SharePoint 2010

Microsoft Dynamics NAV

How To Integrate SAP Business Data Into SharePoint 2010 Using Business Connectivity Services And LINQ to SAP

K2 blackpearl vs. K2 blackpoint

Distributed File System Replication Management Pack Guide for System Center Operations Manager 2007

DocAve 6 Service Pack 1 Job Monitor

CRM and Salesforce Product Comparison

Release Preview Guide

Configuring and Administering Microsoft SharePoint 2010 Course 10174B; 5 Days, Instructor-led

Server Consolidation with SQL Server 2008

What s New in Microsoft Dynamics GP 2015 R2. Microsoft Dynamics GP June 2015

Transcription:

Microsoft SharePoint 2010 Professional Developers Evaluation Guide 1 www.microsoft.com/sharepoint

Copyright This is a preliminary document and may be changed substantially prior to final commercial release of the software described herein. The information contained in this document represents the current view of Microsoft Corporation on the issues discussed as of the date of publication. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information presented after the date of publication. This white paper is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED, OR STATUTORY, AS TO THE INFORMATION IN THIS DOCUMENT. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in, or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation. Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property. Unless otherwise noted, the example companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted herein are fictitious, and no association with any real company, organization, product, domain name, e-mail address, logo, person, place, or event is intended or should be inferred. 2009 Microsoft Corporation. All rights reserved. Microsoft SharePoint Server 2010,Microsoft Visual Studio 2010,Microsoft SharePoint Designer 2010, Microsoft Office InfoPath, Microsoft Office Visio are trademarks of the Microsoft group of companies. All other trademarks are property of their respective owners.

Contents Abstract... 1 Introduction... 1 Summary of What s New... 2 Key Types of Solutions Built on SharePoint by Developers... 3 Building Applications on SharePoint... 3 Business Collaborative Applications... 4 User Interface Portal for Line of Business Application Data... 5 Customizing Out-of-Box Workloads... 5 One Web Part Solutions... 8 Improved Developer Productivity with Better Tools... 8 Visual Studio 2010 SharePoint tools... 8 Visual Studio 2010 SharePoint tools extensibility...13 Developer Workstation support for Windows 7 and Windows Vista SP1...14 Upgrading from Visual Studio 2008 extensions for SharePoint to Visual Studio 2010 SharePoint tools...14 SharePoint Designer 2010...16 SharePoint Designer 2010 Workflow Design...18 SharePoint Designer 2010 Business Connectivity Services Design...19 Developer Dashboard...21 SharePoint 2010 Application Lifecycle Management...23 Better Solutions with Rich Platform Services...24 User Interface...25 Building User Interface...27 The SharePoint 2010 Ribbon...27 The SharePoint 2010 Dialog Framework...28 New Silverlight Web Part...29 Data and Programmability...30 www.microsoft.com/sharepoint

SharePoint List Lookups and Relationships...30 Business Connectivity Services...32 LINQ to SharePoint...33 Performance Enhancements...34 Event Enhancements...35 Workflow Enhancements...36 Document Sets...38 SharePoint 2010 API Choices...39 Flexible Deployment Increases the value of SharePoint Solutions...41 Sandboxed Solutions...41 SharePoint Online...43 Upgrading Solutions...43 Learning More...44 Conclusion...44 SharePoint 2010 Developer Walkthroughs...45 Walkthrough 1: Using LINQ to SharePoint from within a Visual web part...45 Walkthrough 2: Building a Web Part for a Sandboxed Solution...54 Walkthrough 3: SharePoint Designer Workflows imported to Visual Studio 2010...63 Walkthrough 4: Accessing List Data using the JavaScript Client OM...88 Walkthrough 5: Creating and Using External Lists in SharePoint 2010... 101 Walkthrough 6: Extending the SharePoint 2010 UI with Silverlight... 111 2 www.microsoft.com/sharepoint

Abstract This evaluation guide is designed to give you an overview of the feature set and extensibility points for Microsoft SharePoint 2010 and an understanding of how the professional developer can use these features and extensibility points to create comprehensive solutions. This guide begins with an overview of the types of solutions that you can build by developing on SharePoint. It then covers the developer tools for SharePoint 2010, the new platform features and the solution deployment enhancements. The guide concludes with six walkthroughs showing example developer customizations in SharePoint 2010. The ultimate goal of this guide is to provide a framework for an effective evaluation of SharePoint 2010 as a solution creation platform. This guide is intended for the professional developer, development lead, and software architect. Also available are an evaluation guide focused on SharePoint 2010 the product and an evaluation guide for the IT Professional. For the latest information about SharePoint 2010, go to http://sharepoint.microsoft.com. For other product information resources, refer to the Learning More section in this guide. Feedback on this guide can be emailed to SP2010FB@Microsoft.com. Introduction Welcome to the professional developers evaluation guide for Microsoft SharePoint 2010. The goal of this guide is to help you gain sufficient knowledge and understanding of SharePoint 2010 to evaluate this product from Microsoft. SharePoint 2010 provides the business collaboration platform for developers to rapidly build solutions using familiar tools while leveraging a rich set of out of the box features. Visual Studio 2010 and SharePoint Designer 2010 make developers more productive and Visual Studio Team Foundation Server delivers support for application lifecycle management. Developers can integrate Line of Business data in SharePoint 2010 with read/write capability delivered by Business Connectivity Services. Sandboxed Solutions can be deployed to a shared hosting environment to limit the impact of unpredictable code to the other applications in use. 1 www.microsoft.com/sharepoint

SharePoint 2010 is a major step forward for SharePoint as a development platform not only because of the richer set of overall features that the platform supports but also because significant investments have been made in the suite of tools to make developers more productive, and also more accessible to developers of all skill levels. This guide will walk you through some of the most compelling enhancements to the SharePoint 2010 platform for developers. Summary of What s New SharePoint 2010 includes numerous new capabilities and features for professional developers most of which are highlighted in this document. Here is a summary of what s new. Developer Productivity Visual Studio 2010 SharePoint Project Types and Items Visual Studio 2010 SharePoint tools extensibility Visual Studio Extensions For SharePoint Upgrade Windows 7 and Windows Vista Operating System Support SharePoint Designer 2010 Developer Dashboard Team Foundation Server 2010 Integration Rich Platform Services SharePoint Ribbon SharePoint Dialogs Silverlight Web Part List Lookups and Relationships Business Connectivity Services LINQ to SharePoint 2 www.microsoft.com/sharepoint

Performance Enhancements Solution Throttling Event Enhancements Workflow Enhancements Client Object Model REST APIs Flexible Deployment Sandboxed Solutions SharePoint Online Upgrading Solutions In this guide we will walk through all of the new features in SharePoint 2010 that pertain to professional software developers. First we will briefly discuss some key types of solutions that can be built by developers by leveraging the benefits of SharePoint 2010. Key Types of Solutions Built on SharePoint by Developers Developers create solutions every day. SharePoint 2010 makes developing those solutions easier, quicker, and more flexible. Much of the work that the developer had to do in the past with earlier versions of SharePoint has been replaced with simple configuration of the SharePoint 2010 platform, use of Visual Studio 2010 and SharePoint Designer 2010 or with calls to the SharePoint API. Building Applications on SharePoint SharePoint as a platform for application development has really spread its wings with the release of SharePoint 2010. Organizations can get greater productivity by capitalizing on the out of the box features and rich extensibility of SharePoint. Visual Studio 2010, SharePoint Designer 2010, and the SharePoint web user interface accelerate development. By providing tools targeted for different types of users and a 3 www.microsoft.com/sharepoint

common way to share work between those tools the development process has become more streamlined. Better connectivity between the tooling in SharePoint 2010 facilitates business analysts and even end users becoming a part of the development process by creating assets that the developer can leverage in the development process. Business Collaborative Applications In organizations there is a whole class of applications which don t fit into the categories of the structured systems that manage relational data for process, control, or production. Collaborative applications are designed to facilitate and even encourage users to work with one another toward a common goal. Office 2010 and related products and technologies including SharePoint 2010 make developing these types of applications quicker and more effective. SharePoint 2010 is a web-based product and that makes it easy for users to access their information from anywhere. The built in document management and list management features with which SharePoint users are familiar have been extended in several key ways to accelerate solutions which have not been easy in the past. Data management enhancements allow for larger list support, better validation, and connectivity to line of business systems. Many scenarios including for tracking defects or incidents in a manufacturing line become easy to solve by creating a few simple forms. Workflow enhancements for performance, stability, and manageability can be leveraged to solicit feedback on the types of causes for the defect and what can be done to mitigate or resolve them. Enterprise Content Management capabilities of the platform allow defects and the analysis to be placed into a records retention policy. All of this can be done with minimal work on the part of the developer to create the lists, construct the workflows, and configure the platform. The updated client applications, including SharePoint Workspace, mean that the mobile workforce in today s business climate can do work whether they re connected to the server or not. This extends the reach of the application from the users in the office to the users out in the field as well. The new tagging and rating support mean that aggregating the wisdom of large numbers of users becomes easier. Popular responses can now be highlighted. Instead of building collaborative applications which served smaller groups of people, the new 4 www.microsoft.com/sharepoint

social features allow larger teams and even the entire organization to find valuable content developed through the collaborative process. We have moved from an era of data into an era of information and with the features of SharePoint 2010 we can move into an era of personal information. User Interface Portal for Line of Business Application Data Just as line of business systems are a key need for organizations, so too are front end systems which can help get information into the core line of business (LOB) systems that drive the transactional and production throughput of the organization. Traditional LOB systems have a core set of users who are well educated in their use and a much broader audience of users who are less trained and whom interact only in limited or occasional ways. The integration of SharePoint 2010 with back end systems through Business Connectivity Services (formerly known as Business Data Catalog), allows SharePoint to be used to deliver data to the LOB systems. For instance, purchase order requests can be routed for approval in SharePoint via a workflow and delivered to the back end system pre-approved. Similarly, a Word form can be created which reads from the LOB system to look up the customer and product descriptions. The end result of the form can be an order in the sales order system. The ability to read information from the LOB system and to write back changes makes it easy to integrate SharePoint 2010 and Office 2010 into your existing back end systems. Customizing Out-of-Box Workloads SharePoint 2010 offers six out of the box workloads as shown in Figure 1. These capabilities make SharePoint a powerful platform for any user and a powerful platform for extension by a developer. 5 www.microsoft.com/sharepoint

Figure 1 SharePoint 2010 Capabilities More detail about each of these workloads can be found in the SharePoint 2010 Evaluation Guide, this Developer Evaluation Guide will overview the extensibility points that developers can customize. Some of the ways that professional developers can customize and extend them as shown in this table: Capability Out of the Box features Extensibility points Sites Communities The capability to store and retrieve both list and document content in an easy and flexible way with connectivity to the Microsoft Office client applications. The capability to locate and interact with people through expertise, relationships, tagging, and rating of content. Web Parts, Master Pages, Pages, Delegate Controls, InfoPath Forms, and solutions leveraging the Word File Conversion Service. Access Services for deploying Access solutions to SharePoint. Predefined searches, search web parts, tagging interfaces, rating interfaces, and custom user interfaces 6 www.microsoft.com/sharepoint

Content Search Insights Composites The capability to manage content whether that content is a web page, a document, or a set of documents and records management of the content that is created. The capability to search content inside and outside of SharePoint including information in structured database systems. The capability to leverage Excel to access and display data on a web page, Dashboards, and Key Performance Indicators to transform raw data into actionable information. The capability for business users to create their own solutions through connection and arrangement of the features of the platform. Custom page types, field controls, content types, document sets, remote blog storage providers, workflows and Word Services. Records management extensibility and Public Web Sites extensibility. Predefined search result transformations, web parts leveraging search for navigation and location of content, and connections to back end systems. Also IFilters and Protocol Handlers. Excel Services, Excel User defined functions, key performance indicators, and dashboards Web parts, workflows and InfoPath Forms Services that increase the tools available for the end user. 7 www.microsoft.com/sharepoint

One Web Part Solutions Web Parts are the simplest building block in SharePoint and developers are often called on to build just one. A web part may be used to add a data viewer to a SharePoint site, to show user interface for a custom process or to show a new kind of social data. The possibilities are broad and web parts are easy to create for SharePoint Server 2010. Improved Developer Productivity with Better Tools Developers will be excited with the rich set of tools for building solutions with SharePoint 2010. Visual Studio 2010 has direct support for the most common kinds of projects that you might want to create in SharePoint 2010 and it has tools for packaging SharePoint solutions as WSP files. SharePoint Designer 2010 includes new support to help make the transition between designers and analysts to developers smoother and more productive. The developer tools and SharePoint 2010 can be run on a workstation operating system including Windows 7 and Windows Vista SP1 rather than requiring a server Operating System for each developer. Visual Studio 2010 SharePoint tools Visual Studio 2010 includes support out of the box for the most common types of projects that you may want to build with SharePoint 2010 as well as new features for more easily defining features, solutions, and wizards to walk through the most common settings for each project type. Visual Studio 2010 has the following project templates built in: Empty SharePoint Project Visual Web Part Sequential Workflow State Machine Workflow Business Data Connectivity Model Event Receiver List Definition Content Type Module (Files) Site Definition 8 www.microsoft.com/sharepoint

Import Reusable Workflow Import SharePoint Solution (WSP) Package Each project is either C# or VB.NET project that contains particular initial project items. You can add typical C# or VB.NET artifacts as well. In addition Visual Studio 2010 includes additional SharePoint project items as items that you can add to any of your projects: Web Part Workflow Association Form Workflow Instantiation Form Application Page List Definition from Content Type List Instance Empty Element User Control The project types and project items in Visual Studio 2010 are shown in Figures 2 and 3. 9 www.microsoft.com/sharepoint

Figure 2 SharePoint Project Types in Visual Studio 2010 10 www.microsoft.com/sharepoint

Figure 3 SharePoint Item Templates in Visual Studio 2010 Each project wizard guides you through the process by asking what site you want to use to deploy and debug your solution. It also asks whether the result of the project will be deployed as a sandboxed solution as shown in figure 4. 11 www.microsoft.com/sharepoint

Figure 4 Project wizard connects the development environment to a SharePoint instance Visual Studio 2010 also includes support for viewing SharePoint 2010 sites through the Server Explorer. You can now use Server Explorer to look at all of the SharePoint settings for sites, lists, content types, workflow associations, and other objects. This allows you to navigate and view SharePoint sites. It simplifies the process of checking code against the implementation in the system because all of the implementation details available to you in the Visual Studio 2010 environment. For document libraries and lists it also gives you quick access to an artifact you view in the Server Explorer with a link to the SharePoint Web UI. Figure 5 shows the Server Explorer with a SharePoint site open. 12 www.microsoft.com/sharepoint

Figure 5 Server Explorer allows you to navigate SharePoint Visual Studio 2010 SharePoint tools extensibility Visual Studio 2010 provides a rich set of project templates and tools that developers can use to create custom SharePoint solutions. Although these SharePoint projects and tools work well for many application development scenarios, there may be times when different or new functionality is needed. In these cases, you can adapt the SharePoint projects and tools in Visual Studio by using a new Visual Studio extensibility Application Programming Interface (API). 13 www.microsoft.com/sharepoint

This API lets you create new SharePoint project items, automate and extend existing SharePoint project items, enhance packaging, validation, deployment and retraction, extend the SharePoint nodes in Server Explorer, and even create new designers. Developer Workstation support for Windows 7 and Windows Vista SP1 SharePoint 2010 makes great advances in the development environments that can be used to create SharePoint solution. In addition to a broader set of tools for developing solutions for SharePoint the requirement to be running on a server operating system has been relaxed so that it is possible to develop applications on a local developer workstation running a client operating system like Windows 7. Support for Windows 7, Windows Vista Service Pack 1, in addition to Windows Server 2008 means that developers can build on a non-server OS locally and then deploy to a server running Windows Server 2008 for integration, testing, and production. It is important to note that SharePoint 2010 is only available as 64 bit version and therefore the operating system, whether client or server, must be a 64 bit version. Upgrading from Visual Studio 2008 extensions for SharePoint to Visual Studio 2010 SharePoint tools Visual Studio 2010 provides developers with many resources to help upgrade their code from Office SharePoint Server 2007 to SharePoint 2010. Projects based on the Visual Studio 2008 workflow project templates are upgraded automatically by Visual Studio 2010 to equivalent projects which still target Office SharePoint Server 2007 but can now be developed in Visual Studio 2010. All other SharePoint projects in Visual Studio 2010 target SharePoint 2010. Projects based on the Visual Studio 2008 extensions for Windows SharePoint Services (VSeWSS) project templates can be upgraded to equivalent projects targeting SharePoint 2010 and continued development on Visual Studio 2010. An upgrade tool is available that upgrades these projects to the new project and packaging format of the Visual Studio 2010 SharePoint tools. Figures 6 and 7 show the wizard that walks you through the upgrade process. 14 www.microsoft.com/sharepoint

Figure 6 Visual Studio Extensions for Windows SharePoint Services Import Step 1 15 www.microsoft.com/sharepoint

Figure 7 Visual Studio Extensions for Windows SharePoint Services Step 2 SharePoint Designer 2010 SharePoint Designer 2010 is a fully functional participant in the solution creation lifecycle for SharePoint 2010. Applications can be created with the SharePoint web user interface and with SharePoint Designer 2010 as complete applications. Or they can be packaged into a SharePoint Solution (WSP) file that can be imported into and further edited by Visual Studio 2010. For example a declarative re-usable workflow can be prototyped in SharePoint Designer 2010 and moved in to Visual Studio 2010. The ability of the farm administrator to control of usage of SharePoint Designer 2010 has been substantially improved. You can now specify which SharePoint Designer features are available at a web application and site collection level. This will make it 16 www.microsoft.com/sharepoint

easier for organizations to allow SharePoint Designer in some areas of a site and restrict it in others. From the perspective of the user of SharePoint Designer the fundamental approach has changed. Instead of being focused on pages and as a HTML/CSS editor, it is been refocused around the artifacts that you create in SharePoint. Sometimes the artifact that you are creating with SharePoint designer is a master page but more often it is the implementation for lists and libraries, workflows, content types, data sources, entities, or site level settings. Figure 8 shows the primary left navigation menu of SharePoint designer which highlights the new focus on SharePoint artifacts. Figure 8 SharePoint Designer navigation is SharePoint Site focused A site dashboard in SharePoint Designer 2010 allows you to see at a glance the basic information about the site. The navigation bar allows you to navigate into more details about the specific lists and libraries. Figure 9 shows the site dashboard for a site including the basic site information, permissions, and sub-sites. 17 www.microsoft.com/sharepoint

Figure 9 SharePoint Designer s Site Dashboard provides an at a glance view of the SharePoint site SharePoint Designer 2010 Workflow Design In SharePoint Designer 2010 the workflow design experience is a perfect example of how a business analyst can access a tool that can be leveraged as the first step in a development cycle. The workflow designer in SharePoint Designer 2010 allows you to specify a set of steps, conditions, and actions that fit together into a sequential workflow. The designer allows you to create complex workflows that include looping and branching by clicking a few buttons in the ribbon. By assembling the out of the box actions and custom actions it is possible to develop workflows which do not require any custom code. The user interface for building the workflow is a full page, artifact model which allows you to develop a workflow like any other SharePoint artifact by referring to other resources and potentially making changes to lists and content types while building the workflow. 18 www.microsoft.com/sharepoint

Those workflows that are developed in SharePoint Designer 2010 can be exported into a SharePoint Solution Package file (WSP) so that they can be imported in Visual Studio 2010 and from there enhanced or changed. Workflows can also be designed in Visio and imported into SharePoint Designer and Figure 10 shows the Approval workflow when visualized with Microsoft Visio. Figure 10 Microsoft Visio can visualize workflows The workflow editor in SharePoint Designer 2010 has two basic modes. A non-reusable workflow mode which uses the specific attributes of a list and embeds those fields, content types, etc., into the workflow and the reusable workflow which can be packaged for redeployment. The non-reusable workflow allows for a simpler design experience when the workflow will only ever need to exist in one place. The reusable workflow can be reused anywhere so therefore does not bring context from the current site and thus requires more work to deliver. Having both allows the developer to decide which workflow solution is best for the specific scenario. SharePoint Designer 2010 Business Connectivity Services Design Workflows operate on SharePoint data or any data that SharePoint can operate on. Business Connectivity Services extends that reach of workflows and other SharePoint 19 www.microsoft.com/sharepoint

features to data outside of SharePoint. SharePoint Designer 2010 makes the process of defining external entities easy. A wizard guides you through making connections to an external system whether it is Windows Communication Foundation (WCF) Service, a Web Service, a.net class, or a database. Once the connection is made you will see a list of the entities. By right clicking on the entity you can have SharePoint Designer automatically generate the actions needed to support the entity. Within just a few minutes you can create the connections for all of the tables in your database and connect those to external lists in SharePoint. Figure 11 shows the AdventureWorks customer entity that was created by connecting to the Microsoft SQL Server AdventureWorks sample database. 20 www.microsoft.com/sharepoint

Figure 11 The Entity information for a database connected customer entity Developer Dashboard Developing any complex system creates the opportunities for unexpected interactions. In most complex systems determining what part of the system is causing a delay or is consuming resources is difficult. SharePoint 2010 solves this problem by providing a developer dashboard which can be turned on as needed. The developer dashboard records and displays performance statistics related to the code that executed to produce the page. Tracking involves both elapsed time as well as the load placed on the system by queries and tracking of exceptions. 21 www.microsoft.com/sharepoint

You can turn on the Developer Dashboard by running the following stsadm command: stsadm -o setproperty -pn developer-dashboard -pv OnDemand Once enabled, you can turn the Developer Dashboard on and off by clicking on the Developer Dashboard action in the upper right corner of any page, see figure 12. Figure 12: Developer Dashboard command By turning on the detailed view via a link in the developer dashboard itself you get a function-by-function level trace of the time that was taken during the page load in addition to the tracing provided by ASP.NET. This allows the developer to pinpoint exactly which components on the page is generating load on the system and which components are causing the page load time. Figure 13 shows both the summary view of the developer dashboard without the extended tracing. 22 www.microsoft.com/sharepoint

Figure13 - The Developer Dashboard Shows the Elapsed Time of Every Operation SharePoint 2010 Application Lifecycle Management The lifecycle for development in SharePoint 2010 includes business analysts as well as end users. End users and analysts develop the foundation for the solution they want in the web user interface and in SharePoint Designer 2010. SharePoint Designer 2010 can export changes into the standard SharePoint Solution Package (WSP) which can be imported into Visual Studio 2010 and used as the starting point for coding development. By connecting the rapid prototyping phase of a project and directly linking it into the development process developer productivity is greatly enhanced. Further, because there is no loss between the work done in the web UI and SharePoint Designer, the end users and business analysts can truly start the development process and turn the artifacts over to the developer when there are features that cannot be created with the web and SharePoint Designer. 23 www.microsoft.com/sharepoint

By connecting the end user and business analyst work with the developer, SharePoint facilitates a rapid development process where the user is encouraged to start the development process. Visual Studio 2010 also supports tight integration with Visual Studio Team Foundation Server which includes both source control and team builds. Figure 14 shows the definition of a specific build definition for SharePoint projects. Figure 14 SharePoint Project Specific build process implemented in Team Foundation Server Better Solutions with Rich Platform Services SharePoint 2010 is a rich platform on which you can build your application. The Microsoft.NET framework provides base level services that developers can import and use through code. The SharePoint 2010 platform extends this with additional libraries and functionality that can be called directly from developer code. SharePoint also 24 www.microsoft.com/sharepoint

provides a set of end user and business analyst tools that integrate tightly into the features and APIs available to developers. Figure 15 shows a diagrammatic overview of the components of the platform. Figure 15 The SharePoint Platform User Interface The look and feel of SharePoint has radically changed from earlier versions of the product. In addition to being more accessible to the user it allows for improved extension points and fewer workarounds. The new user interface components that you 25 www.microsoft.com/sharepoint

can extend and build applications with include the fluent UI ribbon and an extensible dialog system. Figure 16 shows the new home page for the default team site template in edit mode. Figure 16 The New SharePoint Home Page with the Enhanced User Interface SharePoint 2010 supports XSLT views which leverage a standard for transformation of information from XML into HTML. XSLT support means that any XSLT editor can help you create compelling views. SharePoint Designer 2010 improves on its support for XSLT view generation by allowing you to edit the template for an individual item or for the overall view. The new XSLT engine provides a mechanism for exporting and reusing list views between sites by removing the requirement that a view be associated by a GUID. Mixing the display content and code has never been so easy. In SharePoint 2010 the dividing line between content and code has been blurred because web parts can now be added as a part of content. This means that you can make your components finer grained, gaining even more re-use. Web Parts are arguably the most frequently used extension point for SharePoint with nearly every project including at least one web part. Developer tooling for creating web 26 www.microsoft.com/sharepoint

parts has been extended to Visual Web Parts which manages an ASP.NET User Control (ASCX) connected to a web part class. This approach allows the developer to leverage the visual designers in Visual Studio 2010 to edit their web parts. This can dramatically improve developer productivity over the previous server control-type, non-visual approaches. Building User Interface SharePoint 2010 leverages wiki concepts for managing content and extends these concepts by allowing for the inclusion of web parts within the wiki pages themselves. In previous versions you were allowed to add web parts to web part zones. In SharePoint 2010 the developer (and the user) has compete control of the user interface including the placement of web parts anywhere on the page. For instance, this means that it is possible to put the results of a survey next to text describing the survey. So the results of code and content can be comingled on the page to create rich live content scenarios. The SharePoint 2010 Ribbon The context sensitive ribbon interface is now integrated into the SharePoint 2010 user experience. Your applications can extend the ribbon interface to include new menu items and options both on a global level and based on the context of the user. Figure 17 shows how SharePoint changes the ribbon when a user selects a list web part. The arrow shows the addition of the List Tools section to the ribbon when the list web part is selected. 27 www.microsoft.com/sharepoint

Figure 17 - SharePoint Server 2010 allows developers to easily control the entire page experience from the menus to the content The user interface now also features a status bar immediately below the ribbon to indicate the status of the page that you are working on. Not only do you have context for where you are on the page by context sensitive menus but the overall settings, status, or errors on the page have a consistent location to be displayed as shown in figure 18. Figure 18 SharePoint Server 2010 has a consistent place to communicate status and errors The SharePoint 2010 Dialog Framework A serious challenge in user interface design for the web is the long page refresh times and the constant switching of context from one page to another. SharePoint 2010 has solved these concerns through the use of AJAX requests for partial updates and by providing a flexible popup dialog framework that allows you to pop up entry boxes on 28 www.microsoft.com/sharepoint

top of the existing page. Instead of having users navigate to a new page and then come back after the data entry is completed the user stays on the same page and a dialog appears above the page. The dialogs are just pages which are loaded with a special master page and are therefore completely customizable by users and developers to meet their needs. Figure 19 shows a new announcement being entered in a dialog over a wiki web page. Figure 19 Web Dialogs provide quick entry and consistent context New Silverlight Web Part There are times when the user interface needs to provide a level of interactivity that is simply not possible with XHTML technologies. That is where Silverlight steps in. Silverlight is the best way to leverage your.net development skills in creating rich interactive experiences for the web. SharePoint now includes native support for Silverlight files. Simply develop your Silverlight application (.XAP) and deploy it to the server. You can then add the Silverlight application to your web page by adding the Silverlight web part and providing the location of the.xap file. The Silverlight application is shown as a part of the page as in the example in Figure 20. 29 www.microsoft.com/sharepoint

Figure 20 Silverlight brings even richer interactivity to SharePoint 2010 Data and Programmability SharePoint provides a wealth of features and services which allow developers to quickly develop solutions to organizational problems. Developers can quickly create solutions with relate data, connect to other systems, manage a process flow, and can be deployed anywhere. SharePoint List Lookups and Relationships In a typical system data is somewhat normalized not all of the system's data exists in one large table or list. Instead data exists in sets of tables or lists which have one entry for each entity across multiple tables. The SharePoint lookup field allows you to connect an identifier of one list and to display a different, friendlier field such as name for users to select. SharePoint 2010 adds the ability to create additional columns which display other fields from another list. In the case of a customer, it is possible to create a lookup on the ID of the other list and not only display the customer name but to also bring across multiple other fields. Figure 21 shows the definition for this customer lookup. 30 www.microsoft.com/sharepoint

Figure 21 SharePoint 2010 allows you to define lookup fields that bring other fields into the list The second major improvement in lookup fields is that they now allow you to enforce relationships. You can choose to reject deletes which would otherwise orphan data or you can have SharePoint automatically cascade deletes so that when you delete a customer all of their invoices are deleted as well. As a result SharePoint 2010 can now be used to create sites which have related data connected in ways familiar to users of traditional database tools with the additional user interface options provided by SharePoint. 31 www.microsoft.com/sharepoint

Business Connectivity Services Business Connectivity Services (formerly known as the Business Data Catalog) provides access to external data sourced from a Line of Business system, web services or other external data provider within SharePoint 2010 and Office 2010 applications. Both SharePoint 2010 and Office 2010 applications have product features that can use external data directly and tools are also provided in SharePoint Designer 2010 and Visual Studio 2010 for working with External Data. Business Connectivity Services is built on the Business Data Catalog that was included in Office SharePoint Server 2007 and adds write capability, new tools, offline caching from Office Client 2010 applications and more. Enhancements in the infrastructure configuration allow you to specify which servers can manage this process, enhance the ability to locate the profile pages created for the entities, and create opportunities for easier connections to existing data sources. External lists also provide a greater level of control for the developer because the table structure, indexing, and access methods can be customized to improve performance of the list or to match internal guidelines. This allows developers to include large lists and tables in existing systems in their solutions with the ability to tune the performance as they better understand how the users will use the tool. Figure 22 shows how the inclusion of BCS creates opportunities to leverage SharePoint features and APIs against your existing line of business data that is available via direct database access or via web services. 32 www.microsoft.com/sharepoint

Figure 22- Architecture of Business Connectivity Services LINQ to SharePoint LINQ is a new data access paradigm which allows users to express SQL like syntax against a variety of data sources. LINQ can improve performance by allowing the back end data source to decide the best way to solve the query. SharePoint now fully supports LINQ for querying lists so that you can query information from the platform in a more condensed, easier to understand format. LINQ also provides strongly typed access to data in Visual Studio offering compile time validation to help avoid runtime errors. Figure 23 shows a LINQ expression targeting SharePoint. 33 www.microsoft.com/sharepoint

Figure 23 Sample method that uses LINQ for SharePoint Performance Enhancements From optimizations in the code and SQL queries being used to generate SharePoint out of the box interfaces, to radical changes in the implementation of views, and greater flexibility for the use of large lists outside of the core data structures, SharePoint 2010 will deliver greater performance by reducing choke points in the software related to size of data, and improve performance due to more optimized queries. SharePoint has been tightened in key spots to yield better performance including XSLT view processing and list data operations. The XSLT views have been optimized to support SharePoint 2010 emphasis on them. SharePoint list data operation improvements include core enhancements as well as the automatic creation of indexes on lists when necessary, and improved time to first byte. In addition, SharePoint s client object model is designed to be batched so that the number of round trips between the browser and the server are reduced to improve the overall performance of the client object model. The use of Sandboxed Solutions (discussed in the section Sandboxed Solutions below) allows for the monitoring and management of solutions at a site collection level to limit the negative impact of a poorly performing SharePoint Solution Package (WSP) file. In addition to the performance monitoring and management for solutions, SharePoint 2010 monitors and manages large running queries via application level settings. These settings allow you to set limits and warnings when the number of records returned from a query is large. There is also an object model override that allows you to enabled developers to bypass these limits and exclusion for a time during the day when the queries are allowed so that large reports can be generated in batch during the 34 www.microsoft.com/sharepoint

evening. Figure 24 shows the Query throttling sections of the Web Application Resource Throttling Dialog. Figure 24 Query Throttling can be configured for users and administrators with warnings and hard limits Event Enhancements In SharePoint 2010 SPListEventReceiver allows you to track events, including when a list is added. SPWebEventReceiver allows you to track web events including webs being added and sites and webs being deleted. Figure 25 shows the Visual Studio 2010 wizard for creating a web event. 35 www.microsoft.com/sharepoint

Figure 25 The Visual Studio Event Receiver Wizard for Web Events Workflow Enhancements In SharePoint 2010 you can associate workflows with a site so you need not associate a workflow instance with a specific item in a list. Site-level workflows are a powerful mechanism to create generic functionality using the power of Windows Workflow Foundation (WF). Prior to SharePoint 2010, workflows had to be associated with a list. This meant that if you found a problem that would be well suited to using workflow that wasn t list or document related, you would have to find some way to associate that workflow with a list. This often led to "dummy" list items only created to be a vehicle for a workflow. With the ability to create a workflow not attached to a list, SharePoint 2010 enables a number of new workflow scenarios that where impossible or difficult. 36 www.microsoft.com/sharepoint

To create a site-level workflow, you pick the Site Workflow option when creating a new workflow with Visual Studio 2010, either by picking one of the workflow project templates, or by adding a new workflow to an existing project. Figure 26: Site-level workflow option Once deployed, site workflow can be started via their initiation page. There is a new action under the site actions menu which will display the site workflow page which is a dashboard where you can see all the site workflows in your site, start site workflow, and monitor their execution. 37 www.microsoft.com/sharepoint

Figure 27: Site workflow page Enhancements also allow you to run rules only workflows in a non-persisted and blocking way. This creates the opportunity to do simple event receiver like activities without the need to write code. All that is necessary is to simply declare a rules only workflow and associate it with a list. Because these workflows are not allowed to persist to the disk they are run quickly. Visio 2010 added support to visualize what step a workflow is in via a Visio diagram. This allows users to see not only the current state of the workflow but how many additional planned steps there are before completion. Document Sets Additionally, SharePoint 2010 includes an Enterprise Content Management (ECM) feature called document sets. Document sets are a folder like entity that can contain other documents and because it is a content type in its own right it can have workflows associated with it as well. 38 www.microsoft.com/sharepoint

Document Sets coupled with workflows creates powerful new scenarios where you can route complex documents for approval. Consider a multi-part proposal that needs to be approved. By attaching a workflow to a child document set content type you can have the whole package managed at once. Document sets also manage shared metadata in the documents contained in the document set so workflows can easily change the properties of all of the documents in a document set. Figure 28 shows a document set that contains two documents. Figure 28 Document Sets allow you to run workflows on sets of documents at the same time SharePoint 2010 API Choices SharePoint 2010 makes SharePoint APIs available on every platform from the web server to the client, by integrating access to non-sharepoint hosted data, and by providing a richer set of tools for creating SharePoint solutions. The platform has gotten broader in the types of applications it can support and deeper in the scenarios that are supported. In SharePoint 2010 there are a number of object models that can be used by developers to access the server. The Client Object Model (Client OM) is a unified model which uses the same or similar programming concepts as the Server Object Model (Server OM). The Client OM can be accessed via web services, via a client (JavaScript) API, and via REST. This paves the way for richer applications by dramatically simplifying accessing SharePoint data from client machines and other machines in the infrastructure. Figure 29 shows the SharePoint object model options. 39 www.microsoft.com/sharepoint

Figure 29 The SharePoint Object Model Options Through the use of Windows Communication Foundation (WCF) based services and ADO.NET Data Services v.1.5 it is possible to access the WCF services via a REST interface. This makes it possible to make a simple web request to get data. This makes it easy to get access to SharePoint data from any client application. The basic C# code to access a REST service (excluding required references) is shown in Figure 30. Figure 30 Loading data from a list via a web request in C# Having the APIs available everywhere makes it possible to integrate to SharePoint from a wide variety of applications whether they are sophisticated implementations including 40 www.microsoft.com/sharepoint

the latest features like WCF, a web based application, or whether they are a legacy application with limited options for integration. By providing a set of similar APIs accessible from a client, the server, or the cloud, the benefits provided by SharePoint are available to all kinds of applications including those on non-windows platforms. Flexible Deployment Increases the value of SharePoint Solutions The need to deliver business solutions as cost effectively as possible has lead organizations to share platforms between applications. Servers and farms are being tasked with supporting dozens of applications, not just one or two applications as they have in the past. This creates challenges for centralized infrastructure teams that are tasked with maintaining a stable platform for all of the developers who are creating solutions. SharePoint 2010 has a set of solutions that are specifically designed to allow for this shared platform scenario like the one run by Microsoft itself in the SharePoint Online offering. Sandboxed Solutions SharePoint 2010 has significant improvements for multi-stakeholder scenarios where it is necessary to provide a level of isolation between different sets of code both from a security perspective as well as from the perspective of maintaining performance. Sandboxed Solutions are SharePoint Solution Package files (WSP files) that are limited in what they can do and in the server resources they can use. What they can do is limited using Process Isolation and Code Access Security limited to the SharePoint Site. The resources they can use are limited by process monitoring, logging and log aggregation. Any individual action is limited and the solution is also given a daily limit of resources. This provides for a complete isolation system that ensures code running in a sandboxed solution cannot reach out to access information beyond the scope of the deployment. Specifically, sandboxed solutions will not be able to make updates to the SharePoint object model beyond the scope of the SPSite object. Farm level and web application level changes are allowed only for read operations. Figure 31 shows how the process works from retrieving the code to returning the results to the user. 41 www.microsoft.com/sharepoint

Figure 31 SharePoint Sandboxed Solution Execution Each Sandboxed Solution is stored in a solution gallery similar to the web part gallery. SharePoint tracks and displays the resource usage as an abstract concept called points. Administrators can set a maximum number of points that a site collection can use through quotas. When the utilization of the site collection exceeds its quota solutions are be temporarily disabled. This prevents a single site collection from consuming all of the resources on the server farm. Resource limits for Sandboxed Solutions are designed to avoid disruption of Document Library users on the same server. Figure 32 shows a site collection with 300 resources allocated and a solution called BadWSP which has consumed 0.12 resources to date. 42 www.microsoft.com/sharepoint

Figure 32 Sandboxed Solution resource management SharePoint Online SharePoint Online is a shared hosting service and in the 2007 version it does not allow for custom code to be uploaded in the standard offering. Custom code is only allowed on dedicated farms and then only after an exhaustive review. Sandboxed Solutions in SharePoint 2010 will enable SharePoint Online to allow user provided code to be installed on the shared platform. This opens a new arena for developers who want to create solutions for their customers who want to use hosting instead of maintaining their own servers. Upgrading Solutions As developers revise solutions on the platform, SharePoint 2010 provides upgrade semantics in the WSP file to allow for seamless upgrade of developer provided solutions from one version to another. The addition of upgrading semantics includes support for including <BindingRedirect> elements in the web.config file to allow redirection from one assembly version to another, the inclusion of a version for features and syntax around upgrade actions that should be performed based on what version range the feature was before being upgraded. A new FeatureUpgrading event is raised when a feature is being upgraded from a previous version to a new version. This allows developers to capture and upgrade any items in the feature which cannot be upgraded via the declarative XML syntax. In addition, new API methods exist to make it easier for developers and administrators to identify which features are activated across the farm and what version those features 43 www.microsoft.com/sharepoint

are. This makes it easy for developers to see where their features are activated and which locations the feature hasn t been upgraded yet. Learning More http://msdn.microsoft.com/sharepoint : SharePoint MSDN Developer Center http://mssharepointforums.com : SharePoint Forums http://mssharepointconference.com : The Microsoft SharePoint Conference http://mssharepointdeveloper.com : Introductory Training For Developing on SharePoint Conclusion Whether the challenge that you are trying to solve is a simple one-off application with a few data tables or the front end for an enterprise solution that drives the organization, SharePoint 2010 and the Office 2010 clients provide the tools you need to manage your data, support your users, and connect the processes. As a developer using SharePoint you are not tied to tediously building interactive edit screens, buried in building architecture, or stymied by building security. Building on the benefits of the SharePoint platform allows you to get more done. 44 www.microsoft.com/sharepoint

SharePoint 2010 Developer Walkthroughs The following code walkthroughs demonstrate some of the new functionality available to developers of SharePoint 2010. Screenshots are provided so that if you do not have a SharePoint 2010 installed machine you can still review the steps that would be taken and the outcome that you would see. Walkthrough 1: Using LINQ to SharePoint from within a Visual web part Exercise Duration: 10 minutes Exercise Overview This example demonstrates how to use the SharePoint LINQ provider to read data from a SharePoint list and render the data using the SPGrid web control. It shows these created in the Visual Web Part designer in Visual Studio 2010. Task 1: Create a new Empty Project and add a Visual Web Part 1. Open Visual Studio 2010 from the Start Programs Visual Studio 2010 menu. 2. Create a new project by using File New Project. 3. Pick the SharePoint 2010 templates. 4. From the SharePoint 2010 templates select the Visual Web Part project template. 5. Use SPLinqSolutionDemo as the name of the project. 6. Use C:\SPHOLs as the location. 7. Press OK to create the project. 45 www.microsoft.com/sharepoint

8. When the SharePoint Customization Wizard dialog appears, select the site you want to deploy the Web Part to. Click the Finish button to complete the project creation process. 46 www.microsoft.com/sharepoint

9. Within Solution Explorer expand VisualWebPart1 and open VisualWebPart1.webpart. a. Set the title element to: SPLinqDemoPart Title b. Set the description element to: SPLinqDemoPart Description 47 www.microsoft.com/sharepoint

Task 2: Generate LINQ to SharePoint proxy class to access list data. 1. Start a Visual Studio 2010 Command Prompt from the Start All Programs Visual Studio 2010 Visual Studio Tools Visual Studio Command Prompt (2010) menu 2. Change the directory to C:\SPHOLS\SPLinqSolutionDemo cd C:\SPHOLS\SPLinqSolutionDemo 3. spmetal.exe is a command line tool that can generate C# or VB.NET classes from a SharePoint site's list definitions. It is similar to wsdl.exe that generates a proxy from a Web Service's WSDL file. 4. Run the following command to generate the LINQ proxy code. spmetal /web:http://<yourservername> /namespace:projects /code:projects.cs 5. Go back to Visual Studio 2010. 6. Right-click on the SPLinqSolutionDemo project in the Solution Explorer and select Add Existing Item. 7. Browse to C:\SPHOLS\SPLinqSolutionDemo and select the Project.cs file that was generated when you ran spmetal. 8. Right-click on the SPLinqSolutionDemo in the Solution Explorer and select Add Reference. 48 www.microsoft.com/sharepoint

9. Click on the Browse tab, navigate to the C:\Program Files\Common Files\Microsoft Shared\Web Server Extension\14\ISAPI folder, and select Microsoft.SharePoint.Linq.dll and select OK. Task 3: Write the code for the Visual WebPart User to access the list data. 1. In Visual Studio 2010 open the SPLinqDemoPartUserControl.ascx file from the Solution Folder by double-clicking on it. 2. Add the following markup to SPLinqDemoPartUserControl.ascx under the <%@ Control... declaration <%@ Import Namespace="Microsoft.SharePoint.WebControls" %> <SharePoint:SPGridView id="spgridview" runat="server" AutoGenerateColumns="false"> <HeaderStyle HorizontalAlign="Left" ForeColor="Navy" Font- Bold="true" /> <Columns> 49 www.microsoft.com/sharepoint

<SharePoint:SPBoundField DataField="Title" HeaderText="Title"></SharePoint:SPBoundField> <SharePoint:SPBoundField DataField="JobTitle" HeaderText="JobTitle"></SharePoint:SPBoundField> <SharePoint:SPBoundField DataField="ProjectTitle" HeaderText="ProjectTitle"></SharePoint:SPBoundField> <SharePoint:SPBoundField DataField="DueDate" HeaderText="DueDate"></SharePoint:SPBoundField> </Columns> </SharePoint:SPGridView> 3. In the Solution Explorer, expand the carat icon next to the SPLinqDemoPartUserControl.asx, and then double-click on the SPLinqDemoPartUserControl.ascx.cs file to open it. 4. Add the following using statements to SPLinqDemoPartUserControl.ascx.cs file after the existing using statements. using System.Linq; using Projects; using Microsoft.SharePoint; using Microsoft.SharePoint.Linq; 50 www.microsoft.com/sharepoint

5. Add the following code to the SPLinqDemoPartUserControl.ascx.cs file (replace the existing Page_Load method). protected void Page_Load(object sender, EventArgs e) { ProjectsDataContext dc = new ProjectsDataContext(SPContext.Current.Web.Url); EntityList<EmployeesItem> Employees = dc.getlist<employeesitem>("employees"); var empquery = from emp in Employees where emp.project.duedate < DateTime.Now.AddMonths(6) select new { emp.title, emp.jobtitle, ProjectTitle = emp.project.title, DueDate = emp.project.duedate.value.toshortdatestring() }; } spgridview.datasource = empquery; spgridview.databind(); Task 4: Deploy and Test the WebPart 1. Right click on your project and select Deploy. 2. Add the web part to a web part page: Click the Edit button to put the page in edit mode. Click Insert Click Web Part Click Custom Click SPLinqDemoPart Title Click Add 51 www.microsoft.com/sharepoint

The rendered web part will look like this. 52 www.microsoft.com/sharepoint

Exercise Summary In this walkthrough you built and deployed a Visual Web Part that uses LINQ to SharePoint to gather data from a SharePoint list. 53 www.microsoft.com/sharepoint

Walkthrough 2: Building a Web Part for a Sandboxed Solution Exercise Duration: 20 minutes Exercise Overview This exercise demonstrates creating a web part that renders and updates list data that is deployed as a Sandboxed Solution. Feature Overview A sandboxed solution can be deployed to a site by a site administrator, without requiring intervention from the farm administrator. The solution has full access to the immediate site and restricted access to system resources and other sites. Task 1: Create Sandboxed Solution Project with a webpart. 1. Open Visual Studio 2010 from the Start Programs Visual Studio 2010 menu. 2. Create a new project by using File New Project. 3. Pick the SharePoint 2010 templates. 4. From the SharePoint 2010 templates select the Empty Project project template. 5. Use SBSolutionDemo as the name. 6. Set the location to be C:\SPHOLs. 7. Press OK to create the project. 54 www.microsoft.com/sharepoint

8. When the SharePoint Customization Wizard dialog appears, select the site you want to deploy the Web Part to. 9. Select the Deploy as a sandboxed solution radio button 10..Press the Finish button to complete the project creation process. 55 www.microsoft.com/sharepoint

11. Right-click on the SBSolutionDemo project in the Solution Explorer and choose Add New Item. 12. Select the Web Part (not the Visual Web Part) template from the SharePoint 2010 templates in the Add New Item dialog. Name it SBWebPart. 56 www.microsoft.com/sharepoint

13. Press OK to close the dialog and add the item to the project. Task 2: Add code to provide querying and rendering functionality. 1. In the Solution Explorer, double-click on the SBWebPart.cs file to open it in the editor window. 2. Add the following using statement after the other using statements. using System.Web.UI.HtmlControls; 3. Add the following variables to the class declaration. DropDownList _ddlprojects = new DropDownList(); TextBox _tbdescription = new TextBox(); TextBox _tbduedate = new TextBox(); 4. Add the following new methods within the class declaration. protected override void OnLoad(EventArgs e) 57 www.microsoft.com/sharepoint

{ } base.onload(e); if (!Page.IsPostBack) GetProjectDetails(); /* Populate the text boxes with the selected project details */ private void GetProjectDetails() { EnsureChildControls(); if (_ddlprojects.selectedvalue!= "-- Select a Project --") { SPList plist = SPContext.Current.Web.Lists["Projects"]; int nprojectid = Convert.ToInt32(_ddlProjects.SelectedValue); SPListItem spliproject = plist.getitembyid(nprojectid); _tbdescription.text = spliproject["description"].tostring(); DateTime duedate = Convert.ToDateTime(spliProject["Due_x0020_Date"]); _tbduedate.text = duedate.toshortdatestring(); } else { _tbdescription.text = String.Empty; _tbduedate.text = String.Empty; } } 5. Add the following CreateChildControls implementation beneath the previous code (replace the existing CreateChildControls method). /* Build the UI and setup events */ protected override void CreateChildControls() { base.createchildcontrols(); Panel parent = new Panel(); parent.style.add("border", "solid 1px Navy"); parent.style.add("background-color", "#EEEEEE"); parent.style.add("width", "250px"); _ddlprojects.id = "ddlprojects"; _ddlprojects.autopostback = true; _ddlprojects.selectedindexchanged += new EventHandler(ddlProjects_SelectedIndexChanged); PopulateProjects(); parent.controls.add(_ddlprojects); Panel panel = new Panel(); Label label = new Label(); label.text = "Description"; panel.controls.add(label); 58 www.microsoft.com/sharepoint

parent.controls.add(panel); panel = new Panel(); panel.controls.add(_tbdescription); parent.controls.add(panel); label = new Label(); label.text = "Due Date"; panel = new Panel(); panel.controls.add(label); parent.controls.add(panel); panel = new Panel(); panel.controls.add(_tbduedate); parent.controls.add(panel); } panel = new Panel(); Button bupdateproject = new Button(); bupdateproject.text = "Update Project"; bupdateproject.click += new EventHandler(bUpdateProject_Click); panel.controls.add(bupdateproject); parent.controls.add(panel); Controls.Add(parent); 6. Add the following code beneath the CreateChildControls method: /* Populate the projects drop down */ private void PopulateProjects() { SPList splprojects = SPContext.Current.Web.Lists["Projects"]; _ddlprojects.items.add("-- Select a Project --"); foreach (SPListItem spli in splprojects.items) { _ddlprojects.items.add(new ListItem(spli.Title, spli.id.tostring())); } } 7. Add the following event handling code beneath the PopulateProjects method: /* Change projects handler */ void ddlprojects_selectedindexchanged(object sender, EventArgs e) { GetProjectDetails(); } /* Update the current project */ void bupdateproject_click(object sender, EventArgs e) { EnsureChildControls(); 59 www.microsoft.com/sharepoint

} int nprojectid = Convert.ToInt32(_ddlProjects.SelectedValue); SPListItem spliproject = SPContext.Current.Web.Lists["Projects"].GetItemById(nProjectID); spliproject["description"] = _tbdescription.text; spliproject["due_x0020_date"] = _tbduedate.text; spliproject.update(); Task 3: Build and Deploy the Sandboxed Solution. 1. Right-click on your project in the Solution Explorer and select Deploy. 2. Browse to your server. Click Site Actions Site Settings. Then click on Solutions (under Galleries), you will see your sandboxed solution deployed and activated. 3. Add the webpart to a webpart page. Click the Edit button to put the page in edit mode. Click Insert Click Web Part Click Miscellaneous Click the SBWebPart Title Click Add 60 www.microsoft.com/sharepoint

4. Now you will see the web part running in the Sandboxed Solution. Click the drop down to select a project. The description and due date fields are both updatable. 61 www.microsoft.com/sharepoint

Exercise Summary In this walkthrough you built and deployed a Web Part that runs in the context of a Sandboxed Solution. 62 www.microsoft.com/sharepoint

Walkthrough 3: SharePoint Designer Workflows imported to Visual Studio 2010 Exercise Duration : 20 minutes Exercise Overview This exercise shows how to create a custom workflow activity used by a SharePoint Designer reusable workflow and deploy them together as a single *.WSP. It also shows how to import that whole workflow model into Visual Studio 2010. Feature Overview SharePoint Designer allows creating a workflow that is reusable across multiple lists and multiple sites. The workflow can be exported as a SharePoint Solution File (*.WSP). Task 1: Create and Prepare Project 1. Open Visual Studio 2010 from the Start Programs Visual Studio 2010 menu. 2. Create a new project by using File New Project. 3. Pick the SharePoint 2010 templates. 4. From the SharePoint 2010 templates select the Empty Project template. 5. Use SPDWorkflowDemo as the name. 6. Set the location to be C:\SPHOLs. 7. Press OK to create the project. 63 www.microsoft.com/sharepoint

8. When the SharePoint Customization Wizard dialog appears, select Deploy as a farm solution, and press Finish. 64 www.microsoft.com/sharepoint

Task 2: Create a new Workflow Activity for use by the Reusable Workflow 1. Right-click on the SPDWorkflowDemo solution in the Solution Explorer and select Add New Project. 2. Under the Visual C# Workflow project templates, select the Workflow Activity Library template. 3. Name the project SPDActivityDemo and press OK to add the project to the SPDWorkflowDemo solution. 65 www.microsoft.com/sharepoint

4. Right-click on the SPActivityDemo project in the Solution Explorer and select Add Reference. 5. Under the.browse tab, browse to C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI and select both Microsoft.SharePoint.dll and Microsoft.SharePoint.WorkflowActions.dll. 6. Press OK to add these two references to the SPDActivityDemo project. 7. Right-click on the Activity1.cs (under the SPActivityDemo project in the Solution Explorer) and select rename. 8. Rename the file CreateDocumentLibrary.cs. 9. Select Yes when the Microsoft Visual Studio dialog appears to allow Visual Studio to re-factor the code. Task 3: Add code to create a document library based on parameters passed to our activity. 66 www.microsoft.com/sharepoint

1. Right-click on the CreateDocumentLibrary.cs activity and select View Code. 2. Change the CreateDocumentLibrary base class from SeqeuenceActivity to : Activity public partial class CreateDocumentLibrary: Activity 3. Add the following using statements to the activity: using Microsoft.SharePoint; using Microsoft.SharePoint.Workflow; using Microsoft.SharePoint.WorkflowActions; 4. Add a new DependencyProperty to the CreateDocumentLibrary class named UrlProperty of type string. (Hint - type wdp inside of the class definition and then tab twice - this will create the DependencyProperty using the built-in Workflow Dependency Property snippet) This will be the location where the document library will be created. public static DependencyProperty UrlProperty = DependencyProperty.Register("Url", typeof(string), typeof(createdocumentlibrary)); [DescriptionAttribute("Url of base site")] [CategoryAttribute("Input Property")] [BrowsableAttribute(true)] [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibil ity.visible)] [ValidationOption(ValidationOption.Required)] public string Url { get { return ((string)(base.getvalue(createdocumentlibrary.urlproperty))); } set { base.setvalue(createdocumentlibrary.urlproperty, value); } } 5. Add a new DependencyProperty of type string to the activity named DocLibNameProperty. This will be the name of the document library created by the activity. 67 www.microsoft.com/sharepoint

public static DependencyProperty DocLibNameProperty = DependencyProperty.Register("DocLibName", typeof(string), typeof(createdocumentlibrary)); [DescriptionAttribute("Used as doc lib name")] [CategoryAttribute("Input Property")] [BrowsableAttribute(true)] [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibil ity.visible)] [ValidationOption(ValidationOption.Required)] public string DocLibName { get { return ((string)(base.getvalue(createdocumentlibrary.doclibnameproperty))); } set { base.setvalue(createdocumentlibrary.doclibnameproperty, value); } } 6. Add the following code inside of the CreateDocumentLibrary class: protected override ActivityExecutionStatus Execute(ActivityExecutionContext executioncontext) { CreateDocLib(); return ActivityExecutionStatus.Closed; } private void CreateDocLib() { using (SPSite sps = new SPSite(Url)) { using (SPWeb spw = sps.rootweb) { Guid ID = spw.lists.add(doclibname, DocLibName + " Document Library", SPListTemplateType.DocumentLibrary); SPList spdl = spw.lists[id]; spdl.onquicklaunch = true; spdl.update(); } } } Task 4: Configure activity for deployment. 68 www.microsoft.com/sharepoint

1. To deploy the assembly to the GAC with your SharePoint project you need to configure the project to have a strong-name. 2. Right-click on the SPActivityDemo project and select Properties. 3. Click on the Signing tab in the properties page. 4. Select New under the Choose a strong name key file text from the combo box. 5. Type key as the Key file name value, uncheck Protect my key file with a password and press OK. 6. Build your project (CTRL-SHIFT-B or use Build Build Solution) and fix any errors. 7. Right click on the SPDWorkflowDemo project and click Add SharePoint Mapped Folder. 69 www.microsoft.com/sharepoint

8. Browse to Template\1033\Workflow and select OK to add the mapped folder to the SPWorkflowDemo 9. Right-click on the SPDWorkflowDemo folder in the Solution Explorer (under the Workflow folder). 10. Right-click on the Workflow folder and select Add New Item. 11. Select XML File from the list of Installed Templates, name the file SPDActivityDemo.ACTIONS and select OK to add the file. 70 www.microsoft.com/sharepoint

12. Replace the contents of SPDActivityDemo.ACTIONS with the following XML <WorkflowInfo> <Actions Sequential="then" Parallel="and"> <Action Name="Create Document Library" ClassName="SPDActivityDemo.CreateDocumentLibrary" Assembly="SPDActivityDemo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1a4a7a2c3215a71b" AppliesTo="all" Category="Labs"> <RuleDesigner Sentence="Document Library Name %1 to site %2."> <FieldBind Field="DocLibName" Text="Document Library Name" DesignerType="TextArea" Id="1"/> <FieldBind Field="Url" Text="Url of base site" Id="2" DesignerType="TextArea"/> </RuleDesigner> <Parameters> <Parameter Name="DocLibName" Type="System.String, mscorlib" Direction="In" /> <Parameter Name="Url" Type="System.String, mscorlib" Direction="In" /> </Parameters> 71 www.microsoft.com/sharepoint

</Action> </Actions> </WorkflowInfo> 10. IMPORTANT - Update the PublicKeyToken within the.actions file with the public key token from SPDActivityDemo.dll. Do not use the PublicKeyToken in this example. Ensure you generate your own. 11. To find the PublicKeyToken start a Visual Studio 2010 Command Prompt from the Start All Programs Visual Studio 2010 Visual Studio Tools Visual Studio Command Prompt (2010) menu 12. Type the following command: sn -tc:\sphols\spdworkflowdemo\spdactivitydemo\bin\debug\spdactivitydemo.dll clip 13. In the of SPDActivityDemo.ACTIONS file highlight the value of the PublicKeyToken ("1a4a7a2c3215a71b") and paste (CTRL-V). 14. Remove all the pasted text except the value of your public key. Make sure there are no extra spaces or line feed characters after the public key token (the quote needs to be next to the value of the public key token). 15. Highlight the whole value of the Assembly attribute and copy that value to the clipboard (CTRL-C). Task 5: Add the SPDActivityDemo activity to be deployed with SPDWorkflowDemo. 1. In the Solution Explorer, under the SPDWorkflowDemo project, double-click on Package folder 2. In the Package designer click on Advanced (at the bottom of the designer in the middle pane). 3. Click on the Add button. 4. Click on the ellipses button in the Add Custom Assembly dialog. Browse to the SPDActivityDemo.dll file (C:\SPHOLS\SPDWorkflowDemo\SPDActivityDemo\bin\debug). 5. Within Safe Controls add the following: Assembly Name: SPDActivityDemo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=YOURPUBLICKEY ensure you use a Public Key Token you generated using the sn.exe utility. (Hint - you can paste the value you copied to the clipboard in the last step here). 72 www.microsoft.com/sharepoint

Name Space: SPDActivityDemo Safe: Checked Type Name : * 6. Select OK to add the assembly as part of the SharePoint project deployment package. Task 6: Configure a Feature using Feature Designer 1. Right-click on SPDWorkflowDemo project Features folder and select Add Feature. 2. Right-click on the Feature1 node and select Rename. Rename it to SPDWorkflowDemoFeature. 3. In the Feature designer change the value of the Scope combo box to WebApplication. 4. Change the feature title to SPDWorkflowDemoFeature. 73 www.microsoft.com/sharepoint

Task 7: Add and code a Event Receiver for the Feature 1. Right-click on the SPDWorkflowDemoFeature in the Solution Explorer and select Add Event Receiver 74 www.microsoft.com/sharepoint

2. Add a using statement to the top of the code file that appears in the editor: using Microsoft.SharePoint.Administration; 3. Add the following code to your FeatureReceiver class declaration: public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPWebApplication wappcurrent = (SPWebApplication)properties.Feature.Parent; SPWebConfigModification modauthorizedtype = new SPWebConfigModification(); modauthorizedtype.name = "AuthType"; modauthorizedtype.owner = "SPDActivityDemo"; modauthorizedtype.path = "configuration/system.workflow.componentmodel.workflowcompiler/authori zedtypes"; modauthorizedtype.type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode; 75 www.microsoft.com/sharepoint

modauthorizedtype.value = @"<authorizedtype Assembly=""SPDActivityDemo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=YOURPUBLICKEYTOKEN"" Namespace=""SPDActivityDemo"" TypeName=""*"" Authorized=""True"" />"; wappcurrent.webconfigmodifications.add(modauthorizedtype); wappcurrent.webservice.applywebconfigmodifications(); } 4. Note: You will need to update the YOURPUBLICKEYTOKEN section in the above code with the correct key from the SPDActivityDemo.ACTIONS file. 5. Build and Deploy the SPDWorkflowDemo project by right-clicking on the SPDWorkflowDemo project in the Solution Explorer and select Deploy. Task 8: Create a re-usable workflow using SharePoint Designer 1. Start SharePoint Designer 2010 from the start menu under All Programs Microsoft Office Microsoft SharePoint Designer 2010. 2. Click the Open Site button, and put in the address of the site you used to deploy the SPDWorkflowDemo project to as the Site Name. Press Open twice. Once to open the site, the second to cause SharePoint Designer to open the site at the root level. 76 www.microsoft.com/sharepoint

3. Click on the Workflows node in the navigation pane on the left. 4. Click the Workflows tab in the ribbon. 5. Click the Reusable Workflow button in the Workflows ribbon. 6. Enter SPDWorkflow as the name of the workflow, and press OK to create the workflow. 77 www.microsoft.com/sharepoint

7. Click the Workflow ribbon, then click Actions and scroll down to Labs and click Create a Document Library. Note: This is the activity you created in Visual Studio 2010 previously 78 www.microsoft.com/sharepoint

8. Click the Fx button and select Current Item:Title as the document library name and type in http://servername as the Url of the base site. Click Save 79 www.microsoft.com/sharepoint

9. Save the workflow (click the Save button or press CTRL-S). 10. Click the Workflows in the Navigation pane on the left again. 11. Highlight the SPDWorkflow in the right pane. 12. Click the Workflow Ribbon again. 13. Click Save as Template to save the.wsp file in the Site Assets Library SharePoint list. 80 www.microsoft.com/sharepoint

14. Go back to Visual Studio 2010. 15. In the Server Explorer (if not visible, go to View Server Explorer), expand SharePoint Connections 16. Find your site. If your site isn't visible, right-click on SharePoint Connections and select Add Connection. Type in the URL of your site and press OK. 17. In your site, expand Lists and Libraries Document Libraries 18. Right-click on Site Assets and select View in Browser. 81 www.microsoft.com/sharepoint

19. Once the Site Assets library appears in the browser, click on the menu to the right of SPWorkflow. 20. Click Send To Download a Copy 82 www.microsoft.com/sharepoint

21. Save the SPDWorkflow.wsp file to the C:\SPHOLS directory. Task 9: Import the reusable workflow into Visual Studio 1. Return to Visual Studio 2010. 2. Right-click on the SPDWorkflowDemo solution, and select Add New Project. 3. From the SharePoint 2010 project templates, pick the Import Reusable Workflow project template. 4. Name the project SPDWorkflowImport. 5. Press OK. 6. On the SharePoint Customization Wizard dialog, make sure the site is the same as the site you deployed the SPDWorkflowDemo project to earlier. 7. Select Deploy as farm solution. 8. Press Next. 9. In the next dialog, browse to C:\SPHOLS and select SPDWorkflow.wsp as the template. 83 www.microsoft.com/sharepoint

10. Click Next. 11. On the next dialog, press Finish. 12. Right-click on the SPDWorkflowImport project in the Solution Explorer and select Add Reference. 13. Select the Projects tab and select to reference the SPDActivityDemo project. This is necessary because the newly imported workflow uses the custom activity from that project. 14. Double click on Package folder in the SPDWorkflowDemo project. 15. In the Package designer select the Converted workflows feature in the Items in the Solution pane 16. Click the add button ( > ) to move that feature to Items in the Package pane. This will cause this feature to be deployed with the solution. 84 www.microsoft.com/sharepoint

17. Right-click on the SPDWorkflowDemo project in the Solution Explorer and select Deploy. Task 10: Associate the workflow with a list in SharePoint 1. Open the site you've deployed this project to (HINT - you can right-click on the site in the Server Explorer as a short-cut). 2. Create a new custom list named Customers. 3. Configure the list workflow settings as follows: 85 www.microsoft.com/sharepoint

4. Create a new customer list item with the Title of Contoso. A new document library of the same name should be created automatically. 86 www.microsoft.com/sharepoint

Exercise Summary In this walkthrough you built a new Workflow activity for use in SharePoint Designer workflows. You built a reusable workflow in SharePoint Designer and used the custom activity. You then imported that reusable workflow into Visual Studio 2010 and deployed the final workflow back into SharePoint. 87 www.microsoft.com/sharepoint

Walkthrough 4: Accessing List Data using the JavaScript Client OM Exercise Duration: 30 minutes Exercise Overview This example illustrates how to use the ECMAScript client side object model to update and read list data dynamically. Also shown is how to use the new Dialog API s from client side script. Feature Overview The JavaScript client side object model allows JavaScript developers access to SharePoint objects such as Site, Web and List (and more) from client side JavaScript. Task 1: Create a new Empty Project and add a web part. 1. Open Visual Studio 2010 from the Start Programs Visual Studio 2010 menu. 2. Create a new project by using File New Project. 3. Pick the SharePoint 2010 templates. 4. From the SharePoint 2010 templates select the Visual Web Part template. 5. Use ScriptOMExample as the name. 6. Set the location to be C:\SPHOLs. 7. Press OK to create the project. 88 www.microsoft.com/sharepoint

8. On the SharePoint Customization Wizard dialog, type the address of the site you want to deploy to, and select to deploy this as a farm solution. 9. Click Finish to proceed. 89 www.microsoft.com/sharepoint

10. In the Solution Explorer expand the VisualWebPart1 item, and open VisualWebPart1.webpart by double-clicking on it. a. Set the value of title element to: ScriptOMPart Title b. Set the value of description element to: ScriptOMPart Description 90 www.microsoft.com/sharepoint

Task 2: Add scripting code to access and render SharePoint list data. 1. In the Solution Explorer, open the VisualWebPart1Control.ascx by double-clicking on it. Add the following the following markup code at the bottom of the file. <SharePoint:ScriptLink ID="ScriptLink1" runat="server" Name="sp.js" Localizable="false" LoadAfterUI="true" /> <script language="ecmascript" type="text/ecmascript"> </script> 2. Add the following JavaScript code within the Script block (before the closing </script> tag). This code declares important variables our code will use later on and adds our Initialize() function to be called after all of the SharePoint client side objects have loaded. 91 www.microsoft.com/sharepoint

/* SharePoint list names */ var ContactsListName = "Contacts List"; var CompanyListName = "Company List"; /* SharePoint list field names */ var CompanyNameField = "Title"; var CompanyPhoneField = "Company_x0020_Phone_x0020_Number"; var CompanyDescriptionField = "Company_x0020_Description"; var ContactFirstNameField = "First_x0020_Name"; var ContactTitleField = "Title"; var ContactLastNameField = "Last_x0020_Name"; var ContactEmailField = "E_x002d_Mail"; var ContactCompanyListField = "Company_x0020_List"; /* List objects */ var contactslist; var companylist; /* variable to hold list items from the contactslist */ var contacts; /* client context object - used to access SharePoint data */ var context; /* web (SPWeb) that our page is running on */ var web; /* variable to hold modaldialog to close later */ var modaldialog; /* used when creating a new contactlistitem need to reference the Id field for setting the fieldlookupvalue. */ var companylistitem; var copyofaddcompanyform; /* our startup method when the page loads */ _spbodyonloadfunctionnames.push("initialize()"); 3. Add the following JavaScript code within the Script block below the previous code. Our Initialize() function retrieves the SharePoint ClientContext object and loads up the contacts list, company list and initializes contacts (Contacts list items). /* Initialize useful variables and retrieve ClientContext */ function Initialize() { /* Retrieves the current ClientContext object */ 92 www.microsoft.com/sharepoint

context = SP.ClientContext.get_current(); web = context.get_web(); // Get references to the lists we will use contactslist = web.get_lists().getbytitle(contactslistname); companylist = web.get_lists().getbytitle(companylistname); // Get the list items for the contacts list contacts = contactslist.getitems(); // context.load tells the object model to load the objects scalar // properties. Otherwise they will not be accessible } context.load(contacts); context.load(contactslist); context.executequeryasync(onlistsloaded); 4. Add the following JavaScript code within the Script block below the previous code. The onlistsloaded() event is called asynchronously from the Initialize() function. /* Event handler called loading the contacts and companies lists This method dynamically renders an HTML table to display the list data */ function onlistsloaded() { var contactcount = contactslist.get_itemcount(); var companytable = document.getelementbyid("tblcompanylist"); // clear out the table so when we add a new company there are not duplicates while (companytable.rows.length > 0) companytable.deleterow(companytable.rows.length - 1); var row = new Array(); var content; var cell; var tbo = document.createelement('tbody'); // Loop for each contact for (contactindex = 0; contactindex < contactcount; contactindex++) { // For each contact create a row in the table row[contactindex] = document.createelement('tr'); // itemat() retrieves the listitem var contactli = contacts.itemat(contactindex); // get_item() retrieves the listitem value // if the listitem value is from a lookup field we call get_lookupvalue() var companyname = contactli.get_item(contactcompanylistfield).get_lookupvalue(); 93 www.microsoft.com/sharepoint

var companyphone = contactli.get_item(companyphonefield).get_lookupvalue(); var companydesc = contactli.get_item(companydescriptionfield).get_lookupvalue(); var companycontact = contactli.get_item(contactfirstnamefield) + " " + contactli.get_item(contactlastnamefield); var companycontactemail = contactli.get_item(contactemailfield); // add the cells for the row cell = document.createelement('td'); content = document.createtextnode(companyname); cell.appendchild(content); row[contactindex].appendchild(cell); cell = document.createelement('td'); content = document.createtextnode(companyphone); cell.appendchild(content); row[contactindex].appendchild(cell); cell = document.createelement('td'); content = document.createtextnode(companydesc); cell.appendchild(content); row[contactindex].appendchild(cell); cell = document.createelement('td'); content = document.createtextnode(companycontact); cell.appendchild(content); row[contactindex].appendchild(cell); cell = document.createelement('td'); content = document.createtextnode(companycontactemail); cell.appendchild(content); row[contactindex].appendchild(cell); // Add the row to the table body tbo.appendchild(row[contactindex]); } // add the table body to the table companytable.appendchild(tbo); } 5. Add the following JavaScript code within the Script block below the previous code. The ShowAddCompany() function finds the divaddcompanyelement (which we ll add later) and displays it using the ModalDialog.showModalDialog() method. /* Hide the modal dialog and display the updated UI */ function oncontactadded() { HideAddCompany(); } /* Show a modaldialog with the contents of divaddcompany */ function ShowAddCompany() { var divaddcompany = document.getelementbyid("divaddcompany"); 94 www.microsoft.com/sharepoint

// showmodaldialog removes the element passed in from the DOM // so we save a copy and add it back later copyofaddcompanyform = divaddcompany.clonenode(true); divaddcompany.style.display = "block"; var options = { html: divaddcompany, width: 200, height: 350, dialogreturnvaluecallback: ReAddClonedForm }; modaldialog = SP.UI.ModalDialog.showModalDialog(options); } /* Close the modaldialog */ function HideAddCompany() { modaldialog.close(); Initialize(); } function ReAddClonedForm() { document.body.appendchild(copyofaddcompanyform); } 6. Add the following JavaScript code within the Script block below the previous code. The AddCompany() function creates a new list item in the Company List. /* Called from the Add Company modal dialog Creates a list item in the Company List list and when that query is executed oncompanyadded creates the contact list item. */ function AddCompany() { var lici1 = new SP.ListItemCreationInformation(); companylistitem = companylist.additem(lici1); companylistitem.set_item(companynamefield, gettbvalue("txtcompanyname")); companylistitem.set_item(companyphonefield, gettbvalue("txtphonenumber")); companylistitem.set_item(companydescriptionfield, gettbvalue("txtdescription")); companylistitem.update(); context.load(companylistitem); // Execute the query to create the company list // oncompanyadded is our call back method called when the call to the server has completed context.executequery(oncompanyadded, OnError); } 7. Add the following JavaScript code within the Script block below the previous code. 95 www.microsoft.com/sharepoint

When the company list item is created we then create the lookup fields for the associated contacts. In the oncontactadded event handler the modal dialog is hidden. /* Called when AddCompany has finished executing Note we have to wait until completion because we need access to companylistitem to set the correct lookupid */ function oncompanyadded(args) { var lici = new SP.ListItemCreationInformation(); var companylookupfield = new SP.FieldLookupValue(); companylookupfield.set_lookupid(companylistitem.get_id()); var contactlistitem = contactslist.additem(lici); contactlistitem.set_item(contacttitlefield, gettbvalue("txtcontacttitle")); contactlistitem.set_item(contactfirstnamefield, gettbvalue("txtfirstname")); contactlistitem.set_item(contactlastnamefield, gettbvalue("txtlastname")); contactlistitem.set_item(contactemailfield, gettbvalue("txtemail")); contactlistitem.set_item(contactcompanylistfield, companylookupfield); contactlistitem.update(); context.executequery(oncontactadded); } /* Hide the modal dialog and display the updated UI */ function oncontactadded() { HideAddCompany(); } 8. Add the following JavaScript code within the Script block below the previous code. Helper functions / Error handler /* Error handler */ function OnError(sender, args) { var spnerror = document.getelementbyid("spnerror"); spnerror.innerhtml = args.get_message(); } /* Helper function - shortcut to the value property of a textbox */ function gettbvalue(elid) { var el = document.getelementbyid(elid); return el.value; } 9. Add the following HTML code below the ending script block tag (</script>) tblcompanylist is an empty table that our script dynamically adds rows/columns to for each contact/company. 96 www.microsoft.com/sharepoint

There is also a link to invoke ShowAddCompany() which will launch a modal dialog box. <div style="font-weight: bold">company List</div> <br /> <table id="tblcompanylist" style="border: solid 1px silver"> </table> <br /> <a href="javascript:showaddcompany()">add a company</a> <br /> <div id="divaddcompany" style="display: none; padding: 5px"> <b>company Information</b><br /><br /> Name <br /> <input type="text" id="txtcompanyname" /><br /> Phone Number<br /> <input type="text" id="txtphonenumber" /><br /> Description<br /> <input type="text" id="txtdescription" /><br /> <b>contact Information</b><br /><br /> Title<br /> <input type="text" id="txtcontacttitle" /><br /> First Name<br /> <input type="text" id="txtfirstname" /><br /> Last Name<br /> <input type="text" id="txtlastname" /><br /> E-Mail<br /> <input type="text" id="txtemail" /><br /> <span id="spnerror" style="color: Red" /><br /> <input type="button" value="add New Company" onclick="addcompany()" /> </div> The markup within divaddcompany will be displayed in a modal dialog that allows the user to input data to create a new company/contact. Task 3: Deploy and test the web part. 1. Right click on the ScriptOMExample project in the Solution Explorer and select Deploy. 2. Add the web part to a web part page: Click the Edit button to put the page in edit mode. Click Insert Click Web Part Click Custom 97 www.microsoft.com/sharepoint

Click ScriptOMPart Title Click Add The rendered web part looks like this: 3. To test the functionality of the web part click the Add a company link and fill out the modal form. 98 www.microsoft.com/sharepoint

4. Click the Add New Company button and the new company will be added to the list dynamically with no post backs. 99 www.microsoft.com/sharepoint

Exercise Summary In this walkthrough you built a Visual Web Part that contains ECMAScript that uses the SharePoint Client Object Model and the SharePoint Dialog Platform to show a model dialog which gathers input for a new list item instance. 100 www.microsoft.com/sharepoint

Walkthrough 5: Creating and Using External Lists in SharePoint 2010 Exercise Duration: 15 minutes Exercise Overview This example illustrates how to create a Business Connectivity Services (BCS) with an external content type using Visual Studio and utilize this content type in a SharePoint external list. Feature Overview An external list is a list based on data from an external system outside of SharePoint such as a CRM system or relational database. Task 1: Create a new Business Data Catalog Model project. 1. Open Visual Studio 2010 from the Start Programs Visual Studio 2010 menu. 2. Create a new project by using File New Project. 3. Pick the SharePoint 2010 templates. 4. From the SharePoint 2010 templates select the Business Data Connectivity Model template. 5. Use BCSExample as the name. 6. Set the location to be C:\SPHOLs. 7. Press OK to create the project. 101 www.microsoft.com/sharepoint

8. On the SharePoint Customization Wizard dialog, type the address of the site you want to deploy to, and select to deploy this as a farm solution. 9. Click Finish to proceed. 102 www.microsoft.com/sharepoint

Task 2: Extend the custom entity to allow updating. 1. Click on the Entity1 Methods area in the designer. 2. This brings up the BDC Method Details window for Entity1. 3. At the bottom of this window (you may need to scroll) find the Add a Method area. 4. Open the combo box on the Add a Method area and select Create Updater Method. 103 www.microsoft.com/sharepoint

5. Select the newly created method called Update to retrieve the properties pane. Change Is Static = True. 104 www.microsoft.com/sharepoint

Task 3: Add the code to store list data in an in memory collection. 1. Right click on Update and select View Code. 105 www.microsoft.com/sharepoint

2. Add the following variable to the Entity1Service class; static Dictionary<string, string> EntityCollection = new Dictionary<string, string>(); This variable will be used to hold the lists state information. A real world application would use a durable system such as a relational database instead. 3. Replace the existing method implementations with the following code: public Entity1Service() { if (EntityCollection.Count == 0) { // Create some test list items. Entity1 e1 = new Entity1(); e1.identifier1 = "e1"; e1.message = "e1 Item Data"; EntityCollection.Add(e1.Identifier1, e1.message); Entity1 e2 = new Entity1(); 106 www.microsoft.com/sharepoint

e2.identifier1 = "e2"; e2.message = "e2 Item Data"; EntityCollection.Add(e2.Identifier1, e2.message); } } public static Entity1 GetEntityById(string id) { // Looks up the Entity information based on the id passed Entity1 entity1 = new Entity1(); entity1.identifier1 = id; entity1.message = EntityCollection[id]; return entity1; } public static IEnumerable<Entity1> FindAllEntities() { // Iterates through our backing List<Entity1> entities = new List<Entity1>(); foreach (String key in EntityCollection.Keys) { Entity1 entity1 = new Entity1(); entity1.identifier1 = key; entity1.message = EntityCollection[key]; entities.add(entity1); } return entities; } public static void Update(Entity1 inparameter1) { // Updates the corresponding item in the collection EntityCollection[inParameter1.Identifier1] = inparameter1.message; } Task 4: Deploy and create an entity backed list based on this example. 1. Right click on the BusinessDataCatalog1 project and select deploy. 2. In the web browser click Site Actions -> View All Site Content -> Create. 3. Beneath Custom Lists click External List. 107 www.microsoft.com/sharepoint

4. Specify CustomList as the name of the new list. Beneath Entity Type click the browse icon. Select the newly created Business Data Type in the list and click OK. The list will render the sample list items we added in the entity s constructor. 108 www.microsoft.com/sharepoint

Selecting an item and pressing edit allows changing of the field which in turn calls the Update method we defined in the custom entity. 109 www.microsoft.com/sharepoint

Exercise Summary In this walkthrough you built an External Content Type in Visual Studio and deployed it to SharePoint 2010 for use in an External List. 110 www.microsoft.com/sharepoint

Walkthrough 6: Extending the SharePoint 2010 UI with Silverlight Exercise Duration: 20 minutes Exercise Overview This example shows how to create a Silverlight Application that uses the SharePoint Client Object model to render SharePoint list data. It also shows how to host that Silverlight Application in the Silverlight web part on SharePoint. Feature Overview The Silverlight Web Part allows developers and users to easily add Silverlight applications (*.XAP) to SharePoint sites. Client Object Model can be used in Silverlight to access SharePoint programmatically. Task 1: Create a Silverlight Application for the SharePoint Client Object Model. 1. Open Visual Studio 2010 from the Start Programs Visual Studio 2010 menu. 2. Create a new project by using File New Project. 3. Pick the Visual C# Silverlight templates. 4. From the Visual C# Silverlight templates select the Silverlight Application template. 5. Use SPSilverlightExample as the name. 6. Set the location to be C:\SPHOLs. 7. Press OK to create the project. 111 www.microsoft.com/sharepoint

8. When the New Silverlight Application dialog appears, accept all the defaults by pressing OK. 112 www.microsoft.com/sharepoint

9. Right-click on the SPSilverlightExample project in the Solution Explorer and select Add Reference. 10. Go to the Browse tab in the Add Reference dialog, and add a reference to the two assemblies from the specified location: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ClientBin\ The file names are: Microsoft.SharePoint.Client.Silverlight.dll and Microsoft.SharePoint.Client.Silverlight.Runtime.dll. 113 www.microsoft.com/sharepoint

Task 2: Write code to access and render SharePoint List Data 1. Open the Toolbox and expand Silverlight Controls. 2. Drag a DataGrid control onto the Silverlight Designer. 114 www.microsoft.com/sharepoint

3. In the Solution Explorer right-click on Page.xaml and select View Code. 4. Inside the Page.xaml.cs add the following using statement at the top of the file: using Microsoft.SharePoint.Client; 5. Add the following class before the Page class: public class Project { public String Title { get; set; } public DateTime DueDate { get; set; } public String Description { get; set; } } 6. Add the following member to the Page class itself: ListItemCollection _projectitems; 7. Add the following code to the Page Constructor var context = new ClientContext(ApplicationContext.Current.Url); 115 www.microsoft.com/sharepoint

context.load(context.web); var projects = context.web.lists.getbytitle("projects"); context.load(projects); var query = new Microsoft.SharePoint.Client.CamlQuery(); var strquery = "<View><Query><Where><Gt>" + "<FieldRef Name='Due_x0020_Date' />" + "<Value Type='DateTime'>2008-01-1T00:00:00Z</Value>" + "</Gt></Where></Query><ViewFields>" + "<FieldRef Name=\"Title\" /><FieldRef Name=\"Description\" />" + "<FieldRef Name=\"Due_x0020_Date\" />" + "</ViewFields></View>"; query.viewxml = strquery; _projectitems = projects.getitems(query); context.load(_projectitems); context.executequeryasync(onrequestsucceeded, null); 8. Add the following code inside of the Page class after the constructor: private void OnRequestSucceeded(Object sender, ClientRequestSucceededEventArgs args) { // this is not called on the UI thread Dispatcher.BeginInvoke(BindData); } private void BindData() { var list = new List<Project>(); foreach (var li in _projectitems) { list.add(new Project { Title = li["title"].tostring(), DueDate = Convert.ToDateTime(li["Due_x0020_Date"].ToString()), Description = li["description"].tostring() }); } datagrid1.datacontext = list;} This code initializes the SharePoint Silverlight client object model context (ClientContext). It then gets a reference to the Projects list. Runs a simple CAML query against the list to pull all projects with a duedate greater than 1/1/2008. The results are converted into a list of Projects and bound to the Silverlight DataGrid control. 116 www.microsoft.com/sharepoint

Task 3: Deploy and Test using the SharePoint Silverlight web part. To deploy the solution to SharePoint the resulting.xap file needs to be in the C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ClientBin folder. 1. Right click on your project and select properties and select the Build tab. 2. Change the output path to the following: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ClientBin. 3. Build the solution and fix any typos that may have occurred. 4. Add the SharePoint Silverlight web part to a web part page: Click the Edit button to put the page in edit mode. Click Insert Click Web Part Click Authoring Click Silverlight Web Part Click Add 117 www.microsoft.com/sharepoint

5. When prompted type in: /_layouts/clientbin/spsilverlightexample.xap The rendered web part looks like this: 118 www.microsoft.com/sharepoint

Exercise Summary In this walkthrough you built a Silverlight application that accesses SharePoint lists using the Client Object Model. 119 www.microsoft.com/sharepoint