June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries...

41
June 4-8 Orlando

Transcript of June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries...

Page 1: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

June 4-8 Orlando

Page 2: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.
Page 3: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

NET Development on Microsoft Windows SharePoint Services (WSS)

3.0: The WSS Object Model

OFC330

Patrick TisseghemManaging Partner [email protected]

Page 4: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

WSS Object Model Fundamentals

Working Remotely with Lists and Document Libraries

Cross-Site Data Queries

Exploring New WSS Classes

Session Objectives And Agenda

Event Handlers

Page 5: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

Object ModelsWSS 3.0 MOSS 2007

Microsoft.SharePoint.dll Microsoft.Office.Server.dll

Microsoft.Office.Server.Publishing.dll

Microsoft.Office.Server.Policy.dll

Microsoft.Office.Server.Search.dll

Microsoft.SharePoint.Portal.dll

Microsoft.Office.Workflow.Tasks.dll

Microsoft.SharePoint.Publishing.dll

Microsoft.SharePoint.Workflow.Actions.dll

There is also the .NET Reflectoron www.aisto.com/roeder

Download the SDK!!!!

Page 6: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

Where can I use the WSS OM?

WSS Sites

WSS Object Model

Web PartsWeb PagesSmart Clients

Smart andMobile Clients

Web Services

Web PartsASP.NET Custom Controls and User ControlsApplication pagesFeature activation event handlersEvent handlers for lists, doc libs, sites & site collectionsASP.NET applications and Web servicesWindows Forms and Console applications

Page 7: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

HighBackwardCompatibilityWith WSS v2

Some classes are obsolote

-SPGlobalConfig-SPVirtualServer

SPWebServer

SPWebApplication

SPSite

SPWeb

SPList

SPListItem

SPFarm

Page 8: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

SPSite Object

Represents site collectionUser must be authenticated and authorizedunless anonymous access is enabled

Site Collection has an owner

Site Collection contains hierarchy of child site

Page 9: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

SPWeb Objects

Sites accessible through SPWeb objectsOften must use SPSite object to access SPWeb objects

Page 10: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

Calling Dispose

Many WSS OM objects follow IDisposable patternThey use unmanaged resources that must be released

Failure to call Dispose can cause serious memory leakage

Page 11: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

SPList and SPListItem

Lists are modeled using SPList objectsItems modeled using SPListItem objects

Document libraries can be accessed using SPList

Page 12: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

SPFile and SPFolder

Site represents hierarchy of files and foldersFiles represented through SPFile objects

Folders represented through SPFolder objects

What can be done?Discover all files and folders within a site

Add, move, copy, delete files and folders

Return a page to its initial ghosted state

Program against Web Part data on a Web Part Page

Page 13: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

SPDocumentLibrary

Document Library is more than a SPList objectCan convert SPList to SPDocumentLibrary

Make extra functionality accessible

Page 14: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

DEMOExploring SharePoint using the Object Model

Page 15: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

Security-Related Changes

Impersonating using the SPSite constructor

Elevating PrivilegesThe ISecurableObject Interface

Don’t forget: Test your Web Parts with the least security permissions!

Page 16: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

What’s happening by default?

Web Part code is executed with the account of the logged-on userImpersonation done by SharePointHandle this elegantly!

Page 17: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

Impersonating

Constructor of SPSite accepts now an SPUserToken used to impersonate a specific userTokens time out after 24 hoursWeb Part requires SharePointPermission with Impersonate option

Page 18: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

Elevating Permissions

Some aspects of WSS OM require privileged usersRun your code with the SharePoint\System account

Use with care! The behavior has been created by design (not a mistake!)

SPSecurity.RunWithElevatedPrivileges solves many problems

Web Parts must have the ‘SharePointPermission’ to execute this code

Seal your Web Part!

Page 19: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

ISecurableObject Interface

Everybody doing security implements this interfaceSPWeb, SPList, SPListItem

Page 20: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

Example: DoesUserHavePermissions

Page 21: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

DEMOBetter support for security

and OM programming

Page 22: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

Querying Data with CAML

CAML = Collaborative Application Markup LanguageUsed in SharePoint for

Definition of the Sites, Lists and ViewsQuerying of SharePoint content

Executing CAML QueriesSPQuerySPSiteDataQueryLists.asmx

Page 23: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

DEMOExecuting CAML Queries

Page 24: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

Working Remotely with Lists and Documents

Remotely view and edit SharePoint List datahttp://[server]/_vti_bin/Lists.asmxOperations available:

Work with Document Libraries using FrontPage RPC

• AddAttachment• UpdateList• DeleteList• UpdateListItems• GetAttachmentCollection• AddList

• GetListItemChanges• GetListAndView• GetList• GetListCollection• GetListItems• DeleteAttachment

Page 25: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

DEMOAn off-line client for a lists and

document libraries in SharePoint

Page 26: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

WSS v2 vs. WSS v3 Event Handlers

What is an event handlers?An event handler is a .NET assembly containing one or more classes handling events that are triggered by SharePoint

WSS v2only possible for document libraries

executed in an asynchronous manner

WSS v3 events architecture significantly improvedScope has been extended: lists, document libraries, content types, site, site collection

Events supported for incoming email messages

Support for synchronous events and asynchronous events

Synchronous events occur before the fact and are cancel-able

Events are used in other scenariosCustom policies

Features

Page 27: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

Scope of EventsScope Description Base Class

Item in a list or library

Actions users can do in a list include adding, modifying, deleting, check-in and check-out, ...

SPItemEventReceiver

List or library Trap changes to entities of list schema events, supporting list schema operations and the addition or removal of content types.

SPListEventReceiver

Web Events fired at the level of the site (e.g. adding and removing sites, creating and deleting lists)

SPWebEventReceiver

Email Provides a method for trapping the event when a list receives an e-mail message (EmailReceived)

SPEmailEventReceiver

Feature Trap the activation, deactivation, installation, or uninstallation of a Feature

SPFeatureReceiver

Page 28: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

Creating an Event Handler

.NET class libraryReference to Microsoft.SharePoint.dllCustom class inheriting a WSS receiver class

Override base methods

using Microsoft.SharePoint;namespace Demos { public class MyEventHandler: SPItemEventReceiver {

public override void ItemDeleting(SPItemEventProperties properties) { // do something and possibly cancel the event properties.Cancel = true; properties.ErrorMessage = “my message"; }

public override void ItemDeleted(SPItemEventProperties properties) { // do something } }}

Page 29: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

Deploying a WSS v3 Event Handler

Compile class into strong-named assemblyDeploy the DLL in GAC

Register DLL as event handler in WSS v3

The WSS v2 way (only for document libraries)

Programmatically via the object model

Using the new WSS feature framework

Page 30: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

DEMOWSS Event Handlers

Page 31: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

New Classes in WSS OM

NavigationContent TypesRecycle BinVersioningWorkflow

Page 32: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

Navigation

WSS Navigation is extensibleAdd nodes through WSS UIAdds nodes through code

Page 33: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

Content Types

SPContentTypeCollectionSPContentTypeSPContentTypeIdSPFieldLinkCollectionSPFieldLinkSPXmlDocumentCollection

Page 34: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

SPAudit and SPAuditEntry

WSS provides rich auditing supportBut doesn't make auditing usable OOB - you need MOSS

Custom development required to make WSS auditing functional

enable auditing using code

now examine what's in WSS audit log

Page 35: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

DEMONew OM Classes

Page 36: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

Summary

WSS exposes a very rich object modelDon’t forget to clean up your WSS v2 code a bit

And do call Dispose()

Many improvements have been done to remove the many issues regarding security and SharePoint programming

Impersonation is more elegant

Common interface for objects that support ACL’s

Web Services are your way of getting acces to SharePoint remotely

Event handlers are now a major extensibility option

Many many new classes .. And wait ‘till you’ve seen the MOSS object models

Page 37: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

Q&AQuestions?

Page 38: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

Breakout SessionsSession Codes and Titles

Chalk-TalksSession Codes and Titles

Instructor-led LabsSession Codes and Titles

Hands-on LabsHands-on Lab Codes and Titles

Related Content

Page 39: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

Resources

Technical Communities, Webcasts, Blogs, Chats & User Groupshttp://www.microsoft.com/communities/default.mspx

Microsoft Developer Network (MSDN) & TechNet http://microsoft.com/msdn http://microsoft.com/technet

Trial Software and Virtual Labshttp://www.microsoft.com/technet/downloads/trials/default.mspx

Microsoft Learning and Certificationhttp://www.microsoft.com/learning/default.mspx

Page 40: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

Complete an evaluation on

CommNet and enter to win!

Page 41: June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.

© 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. 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 provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.