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

Post on 31-Mar-2015

220 views 0 download

Tags:

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

June 4-8 Orlando

NET Development on Microsoft Windows SharePoint Services (WSS)

3.0: The WSS Object Model

OFC330

Patrick TisseghemManaging Partner U2Upatrick@u2u.net

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

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!!!!

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

HighBackwardCompatibilityWith WSS v2

Some classes are obsolote

-SPGlobalConfig-SPVirtualServer

SPWebServer

SPWebApplication

SPSite

SPWeb

SPList

SPListItem

SPFarm

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

SPWeb Objects

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

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

SPList and SPListItem

Lists are modeled using SPList objectsItems modeled using SPListItem objects

Document libraries can be accessed using SPList

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

SPDocumentLibrary

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

Make extra functionality accessible

DEMOExploring SharePoint using the Object Model

Security-Related Changes

Impersonating using the SPSite constructor

Elevating PrivilegesThe ISecurableObject Interface

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

What’s happening by default?

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

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

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!

ISecurableObject Interface

Everybody doing security implements this interfaceSPWeb, SPList, SPListItem

Example: DoesUserHavePermissions

DEMOBetter support for security

and OM programming

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

DEMOExecuting CAML Queries

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

DEMOAn off-line client for a lists and

document libraries in SharePoint

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

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

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 } }}

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

DEMOWSS Event Handlers

New Classes in WSS OM

NavigationContent TypesRecycle BinVersioningWorkflow

Navigation

WSS Navigation is extensibleAdd nodes through WSS UIAdds nodes through code

Content Types

SPContentTypeCollectionSPContentTypeSPContentTypeIdSPFieldLinkCollectionSPFieldLinkSPXmlDocumentCollection

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

DEMONew OM 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

Q&AQuestions?

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

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

Complete an evaluation on

CommNet and enter to win!

© 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.