A SharePoint Developer
Introduction
Hands-On Lab
Lab Manual
SPCHOL200 – Building Visual Web Parts – C#
This document is provided “as-is”. Information and views expressed in this document, including URL and
other Internet Web site references, may change without notice. You bear the risk of using it.
This document does not provide you with any legal rights to any intellectual property in any Microsoft
product. You may copy and use this document for your internal, reference purposes.
© 2010 Microsoft. All rights reserved.
Page 1
Contents
SPCHOL200 – BUILDING VISUAL WEB PARTS ............................................................................................... 2
Lab Objective .................................................................................................................................................. 2
Additional Resources ....................................................................................................................................... 2
Getting Started ................................................................................................................................................ 3
Logging into the Virtual Machine .................................................................................................................. 3
Locations ..................................................................................................................................................... 3
Lab Pre-requisites ....................................................................................................................................... 3
Copying code samples from Word document ............................................................................................... 4
Code Snippets ............................................................................................................................................. 4
Exercise 1 – Web Part and Linq Walkthrough .................................................................................................. 5
Task 1 - Create a new SharePoint Project ................................................................................................... 5
Task 2 - Generate LINQ-to-SharePoint proxy class to access list data ......................................................... 8
Task 3 - Access the SharePoint list data in Visual Web Part ...................................................................... 10
Task 4 – Build and Deploy the Visual Web Part ......................................................................................... 12
Exercise 2 – Connecting Web Parts ............................................................................................................... 17
Task 1 – Create a new Empty SharePoint Project ...................................................................................... 17
Task 2 – Create the Web Part Connection Interface................................................................................... 20
Task 3 – Create the Provider Web Part ...................................................................................................... 23
Task 4 – Create the Consumer Web Part................................................................................................... 26
Task 5 – Build and Deploy the Web Parts .................................................................................................. 29
Task 6 – Connect the Web Parts ............................................................................................................... 36
Task 7 – Verify the Web Part Connection................................................................................................... 38
Lab Summary ................................................................................................................................................ 39
Page 2
SPCHOL200 – Building Visual Web Parts
Estimated time to complete this lab: 30 minutes
Visual Studio 2010 and SharePoint Foundation 2010 are required for these exercises. These are
installed on the Virtual Machine used in this lab.
Lab Objective
Web Parts are an essential component of ASP.NET technologies used by SharePoint to present
dynamic information to users. Web parts are the most common customization created for SharePoint. A
Web Part is a reusable component that exists on a Web Part Page and can present any type of web-
based information.
The objective of this lab is to learn about how to utilize enhancements available in SharePoint 2010 to
build Visual Web Parts and connect web parts for use in the SharePoint system.
Work with existing Web Parts and Linq.
Connect two web parts.
Additional Resources
This lab includes the following additional resources:
This Lab Manual
SPCHOL200_Manual_CS.docx
This document.
Source Code
Completed\CS\Ex1
Completed\CS\Ex2
Completed lab source
code in C#.
Resources
Resources\CS
Various other
resources used
throughout this lab.
Page 3
Getting Started
Logging into the Virtual Machine
Please log into the virtual machine as the following user:
Username: Administrator
Password: pass@word1
Locations
This Hands-On Lab contains a number of additional resources in fixed locations. By default, it is
assumed that the base HOL Resources directory is C:\Content Packs\Packs\SharePoint 2010
Developer Labs 1.0\SUPPORTING FILES\SPCHOL200\Resources.
The default working folder for this lab is C:\SPHOLS\SPCHOL200
Lab Pre-requisites
Browse to the base HOL directory Supporting Files\SPCHOL200\Resources and execute the
optimize.ps1 PowerShell script:
1. Right click on optimize.ps1 and select Run with PowerShell:
Figure 1 - Execute the PowerShell script
2. This will open a PowerShell window to execute the script. Click “Open” if you get a security
window. Please wait until the PowerShell script completes executing the script and closes the
PowerShell window (this may take a few moments):