Wrox Programmer to Programmer™
Join the discussion @ p2p.wrox.com
Beginning
SharePoint
®
2010
Development
Steve Fox
Fox
$39.99 USA
$47.99 CAN
Programming (.NET/C) / Microsoft Office 2010
Put the power of
SharePoint 2010 into practice
wrox.com
Programmer
Forums
Join our Programmer to
Programmer forums to ask
and answer programming
questions about this book,
join discussions on the
hottest topics in the industry,
and connect with fellow
programmers from around
the world.
Code Downloads
Take advantage of free code
samples from this book, as
well as code samples from
hundreds of other books, all
ready to use.
Read More
Find articles, ebooks, sample
chapters and tables of contents
for hundreds of books, and
more reference resources on
programming topics that matter
to you.
As a first-class platform that has evolved significantly since its
previous release, SharePoint 2010 now provides several advancements
for the developer (native Visual Studio tools support, services and
extensibility enhancements, and APIs), and many new capabilities
(improved data programmability, line-of-business interoperability,
and sandboxed solutions). With this authoritative guide, industry
veteran Steve Fox provides expert guidance on developing applications
as he walks you through the fundamentals of programming, explores
the developer toolset, and provides practical code examples to teach
you how to use many of SharePoint’s new developer features. You’ll
quickly discover how SharePoint’s rich platform supports great
collaboration, extensibility, and interoperability.
Beginning SharePoint 2010 Development:
• Guides you through the creation of your first SharePoint 2010 application
• Addresses working with SharePoint 2010 sites, lists, and Web parts
• Describes developing SharePoint applications using SharePoint
Designer 2010
• Reviews standard and Visual Web parts, as well as data view Web parts
• Details integrating SharePoint with Microsoft
®
Office
• Explains how to secure your SharePoint 2010 applications
Steve Fox is a Technical Evangelist in the Developer Platform Evangelism group
at Microsoft. He presents at many conferences and has written numerous articles.
Wrox Beginning guides are crafted to make learning programming languages
and technologies easier than you think, providing a structured, tutorial format
that will guide you through all the techniques involved.
SharePoint
®
2010 Development
Beginning
Get more out of
wrox.com
Programmer to Programmer
™
Interact
Take an active role online by participating in our
P2P forums @ p2p.wrox.com
Wrox Online Library
Hundreds of our books are available online
through Books24x7.com
Wrox Blox
Download short informational pieces and code
to keep you up to date and out of trouble!
Join the Community
Sign up for our free monthly newsletter at
newsletter.wrox.com
Browse
Ready for more Wrox? We have books and
e-books available on .NET, SQL Server, Java,
XML, Visual Basic, C#/ C++, and much more!
Contact Us.
We always like to get feedback from our readers. Have a book idea?
Need community support? Let us know by e-mailing
Related Wrox Books
Beginning SharePoint 2010 Administration: Windows SharePoint Services 4
and Microsoft SharePoint Server 2010
978-0-470-59712-5
Packed with step-by-step instructions, tips and tricks, and real-world examples, this book dives into the basics of how to install,
manage, and administrate SharePoint 2010 in an effective and secure manner.
Beginning SharePoint 2010: Building Team Solutions with SharePoint
978-0-470-61789-2
Beginning SharePoint 2010: Building Team Solutions with SharePoint provides you with extensive knowledge and expert advice,
empowering you to become a SharePoint champion within your organization.
Beginning Microsoft SharePoint Designer 2010
978-0-470-64316-7
Covering both the design and business applications of SharePoint Designer, this complete Wrox guide brings you thoroughly
up to speed on how to use SharePoint Designer in an enterprise.
Professional SharePoint 2010 Administration
978-0-470-53333-8
Written by a team of SharePoint experts, this book covers installation, upgrading, configuration, architecture and capacity
planning, monitoring, backups, and disaster recovery.
Professional SharePoint 2010 Branding and User Interface Design
978-0-470-58464-4
SharePoint allows influence over key branding issues like site design, how the user interface affects site visitors’ experience,
ease of use, and other branding topics. This book, from a team of SharePoint branding experts, covers it all.
Professional SharePoint 2010 Development
978-0-470-52942-3
This comprehensive book shows readers how to build field-tested solutions and create custom content management applications.
Professional Microsoft FAST Search: Customizing, Designing, and Deploying Search
for SharePoint 2010 and Internet Servers
978-0-470-58466-8
FAST is Microsoft’s intelligent search-based technology that boasts an ability to integrate business intelligence with Search.
This guide provides you with advanced coverage on FAST search and shows you how to use it to plan, customize, and deploy
your search solution, with an emphasis on SharePoint 2010 and Internet-based search solutions.
Real World SharePoint 2010: Indispensable Experiences from 20 SharePoint MVPs
978-0-470-59713-2
Containing contributions from nearly a score of SharePoint MVPs, this book is an anthology of best practices for all areas
of SharePoint 2010.
BEGINNING
SHAREPOINT 2010 DEVELOPMENT
INTRODUCTION xxiii
PART I WELCOME TO SHAREPOINT 2010
Introduction to SharePoint 2010CHAPTER 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3
Getting Started with SharePoint 2010 DevelopmentCHAPTER 2 . . . . . . . . . . . . . . . . . 25
PART I I GETTING STARTED WITH SHAREPOINT 2010 DEVELOPMENT
SharePoint 2010 Developer ToolsCHAPTER 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .69
Common Developer Tasks in SharePoint 2010CHAPTER 4 . . . . . . . . . . . . . . . . . . . . . . 129
Programming Against SharePoint 2010 ListsCHAPTER 5 . . . . . . . . . . . . . . . . . . . . . . . . 159
Building and Deploying SharePoint CHAPTER 6 Web Parts . . . . . . . . . . . . . . . . . . . . . . 217
Creating Your First SharePoint 2010 ApplicationCHAPTER 7 249
PART II I ADVANCED TOPICS FOR SHAREPOINT 2010 DEVELOPMENT
Integrating Line-of-Business Data Using CHAPTER 8
Business Connectivity Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .277
Creating Enhanced User Experiences for SharePoint CHAPTER 9
with Silverlight . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
Developing Service-Oriented Applications for SharePoint 2010CHAPTER 10 . . . . . . .363
Integrating SharePoint with Microsoft OceCHAPTER 11 . . . . . . . . . . . . . . . . . . . . . . . .399
Securing Your SharePoint 2010 ApplicationsCHAPTER 12 433
PART IV APPENDIX
Where to Go from HereAPPENDIX 449
INDEX 451
584637ffirs.indd 1 5/3/10 10:41:36 AM
584637ffirs.indd 2 5/3/10 10:41:36 AM
Beginning
SharePoint
®
2010 Development
584637ffirs.indd 3 5/3/10 10:41:36 AM
584637ffirs.indd 4 5/3/10 10:41:36 AM
Beginning
SharePoint
®
2010 Development
Steve Fox
584637ffirs.indd 5 5/3/10 10:41:36 AM
Beginning SharePoint
®
2010 Development
Published by
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2010 by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 978-0-470-58463-7
ISBN: 978-0-470-88182-8 (ebk)
ISBN: 978-0-470-88183-5 (ebk)
ISBN: 978-0-470-90477-0 (ebk)
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means,
electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108
of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization
through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers,
MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the
Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-
6008, or online at />Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with
respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including
without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or pro-
motional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold
with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services.
If professional assistance is required, the services of a competent professional person should be sought. Neither the pub-
lisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to
in this work as a citation and/or a potential source of further information does not mean that the author or the publisher
endorses the information the organization or Web site may provide or recommendations it may make. Further, readers
should be aware that Internet Web sites listed in this work may have changed or disappeared between when this work was
written and when it is read.
For general information on our other products and services please contact our Customer Care Department within the
United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available
in electronic books.
Library of Congress Control Number: 2010926824
Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related trade dress are
trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other coun-
tries, and may not be used without written permission. SharePoint is a registered trademark of Microsoft Corporation
in the United States and/or other countries. All other trademarks are the property of their respective owners. Wiley
Publishing, Inc. is not associated with any product or vendor mentioned in this book.
584637ffirs.indd 6 5/3/10 10:41:36 AM
For my wife
584637ffirs.indd 7 5/3/10 10:41:36 AM
584637ffirs.indd 8 5/3/10 10:41:36 AM
ABOUT THE AUTHOR
STEVE FOX of Redmond, WA, is a Senior Technical Evangelist in the Developer Platform Evangelism
group at Microsoft. He’s worked in the IT industry for more than 15 years, and has worked in the
areas of natural language, search, developer tools, and, more recently, Office Business Application and
SharePoint development. Fox also presents at both domestic and international conferences (such as
TechEd, PDC, DevConnections, and SAP TechEd, among others), and has written a number of books
such as Professional SharePoint 2007 Development using Silverlight 2 (Indianapolis: Wiley, 2009)
and Microsoft .NET and SAP (Redmond, WA: Microsoft Press, 2009), as well as articles for MSDN
Magazine and other technical magazines.
584637ffirs.indd 9 5/3/10 10:41:36 AM
584637ffirs.indd 10 5/3/10 10:41:36 AM
ABOUT THE TECHNICAL EDITORS
DARRIN BISHOP is a speaker, author, and developer focusing on Microsoft SharePoint Technologies.
He is the president and lead developer for Darrin Bishop Group, Inc., a Midwest-based Microsoft
Partner focusing on SharePoint Technologies, portals, and collaboration. He is the author of The
Rational Guide to Building SharePoint Web Parts (Greenland, N.H: Rational Press, 2008), as well
as several articles in various magazines. Bishop is an international speaker and speaks at many
SharePoint conferences, SharePoint Saturdays, MOSS Camps, and User Groups. He has been work-
ing with SharePoint Technologies since the release of SharePoint Portal Server 2001.
ELI ROBILLARD designs and guides the delivery of global SharePoint solutions as a Principal
Architect at Infusion Development Corporation. He is a SharePoint Server MVP, a co-author of
Professional SharePoint 2007 Development (Indianapolis: Wiley, 2007), founder of the Toronto
SharePoint Users Group, co-chair of the Toronto SharePoint Camp, and past chair of a group of
high-profile industry influencers and early-adopters known as the ASPInsiders. Robillard lives in
Toronto, Ontario, Canada where he also plays music and goes on adventures with Dawn, Irina, and
their dog, Dakota.
KENNETH SCHAEFER is an independent developer and designer focusing on SharePoint and Web-
based solutions.
BRENDON SCHWARTZ has worked in the Atlanta area User Group scene, and is known around
town as one of the Atlanta .NET Regular Guys (
www.devcow.com). He is currently on the INETA
Board of Directors as the Vice President of Technology, and is a Microsoft MVP for ASP.NET.
Today, Brendon works to solve real-world business problems with Microsoft technologies, such as
SharePoint, Office, BizTalk, VSTS, and .NET technologies. In addition to presenting at local User
Groups, he helped create the “Free Training 1,2,3!” series (
www.freetraining123.com) to help
developers learn Microsoft technologies. He presented material at the first SharePoint 1,2,3! event
(
www.sharepoint123.com), along with other members of the Atlanta Microsoft Professionals.
Schwartz has helped on the leadership teams of five different User Groups. At the first Atlanta Code
Camp in 2005, he presented material on ASP.NET mobile controls.
584637ffirs.indd 11 5/3/10 10:41:36 AM
584637ffirs.indd 12 5/3/10 10:41:36 AM
CREDITS
ACQUISITIONS EDITOR
Paul Reese
PROJECT EDITOR
Kevin Shafer
TECHNICAL EDITORS
Darrin Bishop
Eli Robillard
Ken Schaefer
Brendon Schwartz
PRODUCTION EDITOR
Eric Charbonneau
COPY EDITOR
Foxxe Editorial
EDITORIAL DIRECTOR
Robyn B. Siesky
EDITORIAL MANAGER
Mary Beth Wakefield
ASSOCIATE DIRECTOR OF MARKETING
David Mayhew
PRODUCTION MANAGER
Tim Tate
VICE PRESIDENT AND EXECUTIVE
GROUP PUBLISHER
Richard Swadley
VICE PRESIDENT AND EXECUTIVE PUBLISHER
Barry Pruett
ASSOCIATE PUBLISHER
Jim Minatel
PROJECT COORDINATOR, COVER
Lynsey Stanford
COMPOSITOR
Je Lytle, Happenstance Type-O-Rama
PROOFREADER
Beth Prouty, Word One
INDEXER
Johnna VanHoose Dinse
COVER DESIGNER
Michael E. Trent
COVER IMAGE
© Slobo Mitic/istockphoto
584637ffirs.indd 13 5/3/10 10:41:36 AM
584637ffirs.indd 14 5/3/10 10:41:37 AM
ACKNOWLEDGMENTS
WHEN IT COMES TO WRITING A BOOK, no man is an island. It takes countless hours and resources to
compile a book of this nature. That said, I’d like to thank Jim Minatel and Paul Reese for taking on
the project, and to Kevin Shafer for marshaling the book through the editorial and review process.
A number of technical editors helped review chapters, so a big thanks to Darrin, Eli, Ken, and
Brendan. The comments were great and helped create a better end product. They also taught me a
few things along the way.
I’d also like to say a blanket thanks to all of the content and production editors. All of you made
the book possible and, at the end of the day, a much better product for the beginning SharePoint
developer.
On a personal note, I’d like to thank my wife who put up with me locking myself away for hours at
a time. Nicole, you are ever-tolerant and I’m deeply indebted to you.
584637ffirs.indd 15 5/3/10 10:41:37 AM
584637ffirs.indd 16 5/3/10 10:41:37 AM
Contents
INTRODUCTION xxiii
WelCome to sharePoint 201Part i: 0
introduCtion to sharePoint 2010 ChaPter 1: 3
Getting to Know SharePoint 4
Addressing the Needs of the Developer 8
Extension and Enrichment for Developers 9
Breaking It Down for Developers 10
SharePoint 2010: The Platform 12
SharePoint 2010 Capabilities 14
Site Collection and Sites 15
Server APIs and Client APIs 17
Data Modeling and Programmability 18
SharePoint Central Administration 19
Application Management 20
Monitoring 21
Security 21
General Application Settings 21
System Settings 21
Backup and Restore 21
Upgrade and Migration 22
Configuration Wizards 22
Summary 22
Recommended Reading 24
GettinG started With ChaPter 2:
sharePoint 2010 develoPment 25
Core Developer Features for SharePoint 2010 26
Developer Productivity 26
Rich Platform Services 30
Flexible Deployment 32
Key Skills for the SharePoint Developer 34
Your Development Environment 36
Installing and Configuring Windows Server Hyper-V 37
Installing SharePoint Server 2010 42
Getting Familiar with SharePoint 2010 45
Working with SharePoint Sites 46
584637ftoc.indd 17 5/3/10 10:42:24 AM
xviii
CONTENTS
Working with SharePoint Lists 50
Working with SharePoint Web Parts 58
Setting Permissions for a SharePoint Site 63
Summary 64
Recommended Reading 66
GettinG started With sharePoint 2010 develoPmenPart ii: t
sharePoint 2010 develoPer tools 6ChaPter 3: 9
SharePoint Development Across Developer Segments 70
Web-Based Development in SharePoint 71
Site Settings 72
Inline Rich Text and HTML Editing 74
Adding Multimedia to a Site 76
Developing SharePoint Applications Using SharePoint Designer 2010 78
Customizing a Site Page 80
Managing Other Data Sources in SharePoint Designer 85
Using JavaScript in SharePoint Designer 86
Master Pages 91
Developing SharePoint Applications Using Visual Studio 2010 98
Development Using the Expression Blend Suite 116
Summary 126
Recommended Reading 127
Common develoPer tasks in sharePoint 2010 12ChaPter 4: 9
Creating Web Parts 130
Standard and Visual Web Parts 130
Data View Web Parts 133
Creating Lists, Site Columns, and Content Types 135
Working with SharePoint Data 141
Creating Event Receivers 147
Creating aspx Pages 150
Creating Master Pages 153
Summary 157
Recommended Reading 158
ProGramminG aGainst sharePoint 2010 lists 15ChaPter 5: 9
Overview of SharePoint Lists 159
Programmatically Accessing Lists 162
Programming Against Lists Using the Server-Side Object Model 163
Programming Against Lists Using ASP.NET Web Services 171
584637ftoc.indd 18 5/3/10 10:42:24 AM
xix
CONTENTS
Programming Against Lists Using the Client Object Model 186
Programming Against Lists Using a Custom WCF Service 197
REST-Based Services and List Development 202
Creating Event Receivers for a SharePoint List 210
Summary 215
Recommended Reading 216
BuildinG and dePloyinG ChaPter 6: sharePoint
WeB Parts 217
Understanding Web Parts 217
Web Part Architecture 220
Custom Web Parts 223
Visual Web Parts 233
Custom Web Part Properties 244
Summary 246
Recommended Reading 248
CreatinG your First sharePoint 2010 ChaPter 7:
aPPliCation 249
Requirements 250
Solution Design 251
Customer Sales and Total Sales Lists 252
Building the Application 254
Adding a Record to the Sales List 254
Viewing the Customer Sales 258
Viewing the Total Sales 262
Adding a Chart Web Part 268
Final Dashboard 271
Summary 272
Recommended Reading 274
advanCed toPiCs For sharePoint 2010 develoPmenPart iii: t
inteGratinG line-oF-Business data ChaPter 8:
usinG Business ConneCtivity serviCes 277
Understanding Oce Business Applications (OBAs) 278
OBAs and BCS 280
Anatomy of an External Content Type 284
Connectivity Options with BCS 287
Developing Your First Application Using BCS 289
Creating the External Data Source 290
584637ftoc.indd 19 5/3/10 10:42:24 AM
xx
CONTENTS
Creating the External Content Type 291
Setting Permissions for External Content Types 306
Taking the External List Oine 307
Summary 313
Recommended Reading 315
CreatinG enhanCed user exPerienCes ChaPter 9:
For sharePoint With silverliGht 317
Understanding Silverlight 317
Why Integrate Silverlight and SharePoint? 325
Integrating Silverlight with SharePoint 326
No-Touch Integration 328
Low-Touch Integration 331
High-Touch Integration 343
Summary 361
Recommended Reading 362
develoPinG serviCe-oriented ChaPter 10:
aPPliCations For sharePoint 2010 363
ASP.NET Web Services 365
Native Web Service 366
Custom ASP.NET Services 370
WCF Web Services 378
RESTful Web Services 387
Azure and SharePoint 390
Summary 396
Recommended Reading 398
inteGratinG sharePoint ChaPter 11:
With miCrosoFt oFFiCe 399
Content Type as a Document Template 400
Using InfoPath in Your SharePoint Solutions 404
Managing Oce Documents through a SharePoint Workflow 406
Integrating Oce Documents with SharePoint List Data 410
Server-Side Services 418
Visio Services 418
Excel Services 420
Word Services 426
Access Services 427
Summary 429
Recommended Reading 431
584637ftoc.indd 20 5/3/10 10:42:24 AM
xxi
CONTENTS
seCurinG your ChaPter 12:
sharePoint 2010 aPPliCations 433
Authorization 434
Solution Trust 436
Secure Store Service 440
Federated Authentication 442
Forms-Based Authentication 442
Claims-Based Authentication 443
Summary 444
Recommended Reading 446
aPPendiPart iv: x
Where to Go From here 44aPPendix : 9
INDEX 451
584637ftoc.indd 21 5/3/10 10:42:24 AM
584637flast.indd 22 5/2/10 7:11:44 PM
IntroductIon
My fIrst experIence wIth sharepoInt was the task of integrating multiple SharePoint 2003
sites into one all-up organizational portal — a fairly straightforward project that integrated four
sites into one. This one project got me curious, and, in the process, not only exposed me to the
inner workings of SharePoint, but also got me hooked on the technology.
As I learned more about SharePoint, I realized the path was longer than I had originally thought. Since
that time, I’ve seen the platform mature quite a bit, and interest from developers like yourself swell to
what is now a very high rate of growth and adoption. And the market for SharePoint is also growing at
a very rapid pace — one that is currently outpacing the growth of the SharePoint developer community.
What you’ll learn in this book is that SharePoint 2010 has a lot to offer the developer. You can move
from the small-scale development project where you’re building custom Web parts, to the larger,
enterprise-grade solution that leverages Web services and integrates with other Microsoft and non-
Microsoft technologies. This is the incredible part about SharePoint — it is a platform with huge
potential in multiple directions. And, as a beginning SharePoint developer, you should strap yourself
in, because you’re in for a great ride.
who thIs Book Is for
Simply put, this book is aimed at the developer who is new to SharePoint. The book assumes that
you have some programming experience and a passion to learn how to develop for SharePoint. But
this book does not assume that you’ve programmed against SharePoint before. If this somewhat fits
with you, then this book is absolutely for you.
With regard to your general development background, the two assumptions in this book are that
you have some familiarity with Web development, and you have an understanding of .NET pro-
gramming. With regard to Web development, this book assumes that you understand HTML,
and may have an understanding of Cascading Style Sheets (CSS), Extensible Markup Language/
Extensible Stylesheet Language (XML/XSL), and dynamic languages such as JavaScript. You may
have a light understanding of ASP.NET and are looking to apply this knowledge to the SharePoint
space. In any case, you have some understanding of the fundamentals of Web and .NET develop-
ment, and are looking to apply those to the SharePoint space.
what thIs Book covers
SharePoint 2010 is a significant leap forward from the 2007 release, and you will find that there are
a ton of features built into the platform for you to leverage in your solution development. Because
SharePoint is a broad platform that covers a lot, this book also covers quite a bit of ground surface.
As a Wrox Beginning book, the goal of the book is to get you started with many of the fundamen-
tals so that you can continue on to advanced programming beyond this book.
584637flast.indd 23 5/2/10 7:11:44 PM