A
Answers To Exercises
For the end user and the developer, SharePoint is a Web-based collaboration platform for the enterprise and Web. As an end user, you will natively leverage SharePoint to manage your collaborative tasks. As a developer, you will build apps to enhance the end user’s experience to help support different types of scenarios.
You can use default SharePoint apps, such as document libraries, lists, and so on. And you can build custom Apps for SharePoint, such as Web parts, event receivers, workflow apps, and so on.
Excel Services, Business Connectivity Services, Machine Translation Services, and Access Services are examples.
Server-side object model and client-side object model. You use the server-side object model when building applications in SharePoint Server or SharePoint Foundation. You can use the client-side object model for any version of SharePoint.
Work through creating a new site collection using the exercises in the chapter to help guide you. Navigate to your SharePoint administration page and click New ⇒ Private Site Collection. Complete the information in the New Site Collection dialog and as you do, ensure you select the Team Site template in the Collaboration tab. Click OK to create, and once created you can click Site Contents to add lists, document libraries, and other apps.
SharePoint-hosted, Autohosted, and Provider-hosted.
Any Web stack.
You can find an example of this in the SharePoint 2013 SDK. See Chapter 2, “Recommended Reading.”
Visual Studio, SharePoint Designer, and Napa. You can also use tools like Expression Blend for rich design and Fiddler for debugging and tracing.
You would use Visual Studio for managed code development and development that requires ALM or source code control. Napa is for rapid development and prototyping — but the code can also be imported into Visual Studio. You use SharePoint Designer for creating, editing and updating Web pages, content types, and so on. You can also use SharePoint Designer for creating rules-based workflow.
Open Visual Studio, and click File ⇒ New Project. Select the Empty SharePoint Project template and then add a SharePoint site URL and select Farm-Level trust for your project. Then, Add a web part project to your empty SharePoint project. Add some simple controls to your Web Part, and then add a breakpoint somewhere in your newly added code. Enter F5 to test and debug the code.
Using Visual Studio 2012, you can create an Empty SharePoint project. Using the Empty SharePoint project as a shell project, you can then add two items to the project: a Standard Web Part and a Visual Web Part. After you’ve done this, add the code from this chapter to create the simple Web Parts. You can hit F6 to build the project, and then deploy the project to your SharePoint site. Both of your Web Parts will be deployed to your SharePoint site, and you’ll be able to use them separately.
You can continue to use the SharePoint project that you used in the first exercise (the project to which you added the two Web Parts), or you can create a new one. Either way, add a new item that is an ASPX Page and then add some simple HTML to the page (for example, <DIV>Hello World!</DIV>). After you’ve completed this, hit F6 to build the project and then deploy to SharePoint.
You can create your own Master Page, or you can download a Minimal Master Page or Starter Master Page. The Minimal Master Page is the most basic Master Page that you can use with SharePoint. You can find information about how to create a Minimal Master Page here: http://msdn.microsoft.com/en-us/library/aa660698(v=office.12).aspx. A Starter Master Page has some additional elements beyond the Minimal Master Page, and these are typically created by the SharePoint community. One example is here: http://startermasterpages.codeplex.com/. Once you’ve downloaded either of these, use SharePoint Designer to create a new Master page, copy and paste the contents of either the minimal or starter page, and then save to your SharePoint site. You can then set the new Master page as the default Master Page using SharePoint Designer, and your new Master page will take effect.
IAAS, PAAS, and SAAS.
Cloud Services, Media Services, Data Services, Web Sites, Data Sync, Hadoop on Azure.
Autohosted and Provider-hosted.
First, create a new SharePoint project (targeting an Office 365 Developer site) and set the project to be Autohosted as you create the project. This provides you with the basic plumbing of an ASP.NET application that you can natively deploy to Office 365 (and of course Windows Azure). After you’ve created the Autohosted application, you can leverage the REST service project you built at the beginning of Chapter 5 or recreate it within the same solution you just created. Either way, deploy the REST service to Windows Azure. After you’ve deployed, you now have a REST endpoint that you can call to use the data that is returned from that service endpoint. You can now add a simple Button control and event to call the REST service to show that you can retrieve the data. Keep it simple to understand the data structure that is returned, such that you can build out the application to leverage the data.
The new SharePoint application model removes code from running within the core SharePoint processes and moves it externally to another host. The new model provides the APIs for authenticating and calling back to SharePoint for data and responding to events.
The SharePoint application model provides the following three areas for integration:
A Web Part’s code is run and rendered by code running in the SharePoint process. An App Part is an iFrame whose contents are rendered on another server.
An application’s permissions are granted when the application is installed. The user installing the application may accept or decline the invitation to grant the permissions the app is asking for.
SharePoint applications can use the provided “Chrome Control” and reference provided style sheets to adopt the same visual styling as SharePoint sites.
The four main components of an .app package are the manifest file, the SharePoint solution, the Web deploy package and the database package.
In a Provider-hosted application the developer of the application is responsible for running the application code himself. This means the SharePoint application package contains the SharePoint solution and manifest only. The code portion of the solution runs wherever the developer hosts it, such as in Azure.
Only two types of components are allowed to be deployed to the host Web during installation of an app: App Parts and Custom UI Actions.
Provider-hosted apps need a manually created client ID and secret prior to submission to the store so that the developer can add them to the application’s back-end code so that the app is running when it is tested by Microsoft.
There are many options for monetizing applications. However, some of the most common are to make the application a paid for product through the store, add ads to the application, and sell in-app purchases in the application.
An application can catch any of the following application life-cycle events: App Installed, App Uninstalling, or App Upgraded.
The three types of CSOM libraries are: .NET Managed, JavaScript and Windows Phone/Silverlight.
OData adds additional filter and query capabilities over and above what is available with the standard REST capabilities.
REST and OData support in SharePoint 2013 provides support for Creating, Reading, Updating, and Deleting data.
By using the provided CSOM libraries, developers can take advantage of the prebuilt batching capabilities to reduce the number and frequency of calls made to SharePoint.
Using either SharePoint Online or SharePoint on premises you can create new application identities using the AppRegNew.aspx page.
The three token types used in SharePoint’s OAuth flow are the context token, access token and refresh token.
When needed, an application may elevate its permissions to those of just the application by using the GetAppOnlyAccessToken helper method to generate an app-only access token.
The refresh token and access tokens can both be cached. The period for which they can be cached should be determined by looking at the expiry date and time passed back from SharePoint for each.
Apps for Office can be written using standard Web technologies hosted on any platform and written in any language.
The new JSOM for Office allows the developer’s Web application to interact with the document or mail item, but does not provide for automation of the Office client.
MailApp, TaskPaneApp, and ContentApp.
You can use various strategies enabled by a number of methods on the Office.context.document.bindings object such as .addFromSelectionAsync, .AddFromPromptAsync, and .AddFromNamedItemAsync.
ProcessOneWayEvent
Enumeration, .CancelWithError and property, and .ErrorMessage.
S2S and OAuth.
You can actually look in two places. One is in the manifest file, and the other is checking to see whether any one of the app life-cycle properties of the SharePoint project is set to True.
OData.
CSOM or REST.
EventSubscriber and EventUnsubscriber.
ECTs can now be deployed as part of an app for SharePoint at the app-level whether the app is Provider-hosted, Autohosted, or SharePoint-hosted.
PowerPoint Automation Services and Machine Translation Services.
The Office Web App Server.
OData.
For an on-premises installation of SharePoint, the data and content are stored in a SQL Server database and for Office 365 they are stored in a Windows Azure SQL Database.
The Service Bus provides durability for event delivery and for messaging using its Pub/Sub pattern.
The App Step action lets the workflow elevate its permissions to perform something on behalf of the user with its own permissions.
The Dictionary type variable.
GetCurrentItemGuid.
Beginning SharePoint® 2013 Development
Published by
John Wiley & Sons, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
Copyright © 2013 by John Wiley & Sons, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 978-1-118-49584-1
ISBN: 978-1-118-49586-5 (ebk)
ISBN: 978-1-118-65477-4 (ebk)
ISBN: 978-1-118-65487-3 (ebk)
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 http://www.wiley.com/go/permissions.
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 promotional 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 publisher 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 publishes in a variety of print and electronic formats and by print-on-demand. Some material included with standard print versions of this book may not be included in e-books or in print-on-demand. If this book refers to media such as a CD or DVD that is not included in the version you purchased, you may download this material at http://book-support.wiley.com. For more information about Wiley products, visit www.wiley.com.
Library of Congress Control Number: 2012955721
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 countries, and may not be used without written permission. Microsoft and SharePoint are registered trademarks of Microsoft Corporation. All other trademarks are the property of their respective owners. John Wiley & Sons, Inc., is not associated with any product or vendor mentioned in this book.
For my wife.
—Steve Fox
For the delights of my life, Heather, Courtenay, and Morgan.
—Donovan Follette
For the loves of my life, Vicki, Sam, and Kate.
—Chris Johnson
ABOUT THE AUTHORS
STEVE FOX is a Director in MCS for Microsoft with more than 17 years of IT experience ranging from natural language to Office and SharePoint and most recently to Windows Azure development. His current focus is enabling the cloud for enterprise organizations.
DONOVAN FOLLETTE is a Sr. Technical Evangelist for Microsoft with more than 25 years of experience designing and building enterprise business applications. His current focus is on developers and helping them wrap their mind around the all-new cloud app model for Office and SharePoint 2013.
CHRIS JOHNSON is an avid developer and a speaker. He is the General Manager of Provoke Solutions, Inc. and a Microsoft Gold Partner in Seattle, Washington, that is one of the world’s most renowned and sought-after online experience consultancies. Provoke Solutions specializes in software solutions for SharePoint and the Microsoft technology stack (http://www.provokesolutions.com). In November 2011, Chris left Microsoft Corporation after nine and a half years where he most recently was a Senior Technical Product Manager for the SharePoint product group in Redmond, Washington, managing SharePoint’s professional developer audience technical marketing programs. Chris moved to Redmond in 2007 to work on the software engineering team on the SharePoint 2010 release after working for Microsoft New Zealand. In New Zealand he consulted for customers across the Asia Pacific region on designing and implementing Content Management Server and SharePoint deployments. Chris’s background is in Microsoft software development and he enjoys all things technical. He is a speaker at numerous conferences around the world such as Tech.Ed, SharePoint Best Practices Conference, SharePoint Connections, and the worldwide SharePoint Conference. Chris holds a Bachelor of Computer Science and enjoys throwing himself out of perfectly good airplanes from time to time. Contact Chris on his blog at www.looselytyped.net.
ABOUT THE TECHNICAL EDITOR
ANDREW CONNELL is a developer, author, instructor, and co-founder of Critical Path Training, a SharePoint education–focused company. He has a background in content management solutions and Web development that spans back to his time as a student at the University of Florida in the late 1990s managing class sites. He has consistently focused on the challenges facing business today to maintain a current and dynamic online presence without having to rely constantly on Web developers or have a proficiency in Web technologies.
Andrew is an eight-time recipient of Microsoft’s Most Valuable Professional (MVP) award (2005–2012) for Microsoft Content Management Server (MCMS) and Microsoft SharePoint Server. He has authored and contributed to numerous MCMS and SharePoint books over the years, including Professional SharePoint 2007 Web Content Management Development (Wrox, 2008), Inside Microsoft SharePoint 2010 (MSPress, 2011) and (Wrox, 2010), and Real World SharePoint 2010 (Wrox), among others, and is the author of numerous articles both for the Microsoft Developer Network (MSDN) and for various magazines.
Andrew has presented at numerous conferences in the United States, Europe, and Australia. You can find Andrew on his blog (www.andrewconnell.com/blog) or follow him on Twitter @andrewconnell.
CREDITS
Acquisitions Editor
Mary James
Project Editor
Victoria Swider
Technical Editor
Andrew Connell
Production Editor
Christine Mugnolo
Copy Editor
Paula Lowell
Editorial Manager
Mary Beth Wakefield
Freelancer Editorial Manager
Rosemarie Graham
Associate Director of Marketing
David Mayhew
Marketing Manager
Ashley Zurcher
Business Manager
Amy Knies
Production Manager
Tim Tate
Vice President and Executive Group Publisher
Richard Swadley
Vice President and Executive Publisher
Neil Edde
Associate Publisher
Jim Minatel
Project Coordinator, Cover
Katie Crocker
Proofreader
Sarah Kaikini, Word One New York
Indexer
Robert Swanson
Cover Designer
Elizabeth Brooks
Cover Image
© Stefano Borsani / iStockphoto
ACKNOWLEDGMENTS
FIRST, thanks to the acquisitions and editorial staff at Wiley. It’s great to continue to work with such a good crew of people. Next, thanks to Andrew Connell for helping steer us in the right direction through technical editing. Also, thanks to Victoria Swider who tirelessly moved us through the editing and production process. Additionally, thanks to the many Microsoft folks who gave their time for technical questions and conversations. And last, thanks to you, the developer community. Without you, this book would not even be possible.
—Steve Fox
THANKS to Andrew Connell, technical editor, for providing his technical expertise and insight and Victoria Swider, project editor, for her patience as the authors juggled busy travel and conference schedules to find time-slices for writing. I would also like to acknowledge my Microsoft colleagues whom I learned much from as Office and SharePoint 2013 were taking shape: Mauricio Ordonez, Rob Howard, Mike Ammerlaan, Rolando Jimenez Salgado, Gareth Pinto, Stephen Oliver, and Brady Gaster. You are all a pleasure to work with and greatly respected. And thanks to you, the reader, My hope is that this book will introduce you to the opportunity for developing a new class of productivity solutions in the form of Apps for Office and SharePoint, and that your solutions, whether built and provided behind the firewall or installed from Office.com, will find their way into the hands of the all-important end users, whose day will be a bit better because they are using your software. Enjoy!
—Donovan Follette
THANKS must go out to our wonderful editors and staff at Wiley for ushering me through my first technical book project. Their patience and flexibility were invaluable given the authors’ hectic day jobs, speaking engagements, and travel schedules. I know at times it was like herding cats! A huge debt of gratitude to the one and only Andrew Connell who provided the elite technical air cover and expertise to keep us all on the straight and narrow and accurate! Thanks to Nick Swan and the team at Lightning Tools for their insights into real-world SharePoint application metrics. Finally, to all the folks at Microsoft who assisted with answering questions, providing support, and generally being really helpful as I wrote this book — Thank you all.
—Chris Johnson