410 likes | 495 Views
OFC330. NET Development on Microsoft Windows SharePoint Services (WSS) 3.0: The WSS Object Model. Patrick Tisseghem Managing Partner U2U patrick@u2u.net. Session Objectives And Agenda. WSS Object Model Fundamentals. Working Remotely with Lists and Document Libraries.
E N D
OFC330 NET Development on Microsoft Windows SharePoint Services (WSS) 3.0: The WSS Object Model Patrick Tisseghem Managing Partner U2U patrick@u2u.net
Session Objectives And Agenda WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Event Handlers Exploring New WSS Classes
Object Models Download the SDK!!!! There isalso the .NET Reflectoron www.aisto.com/roeder
Wherecan I use the WSS OM? • Web Parts • ASP.NET Custom Controls and User Controls • Application pages • Feature activation event handlers • Event handlers for lists, doc libs, sites & site collections • ASP.NET applications and Web services • Windows Forms and Console applications WSS Sites WSS Object Model Web Services Web PartsWeb Pages Smart Clients Smart andMobile Clients
SPFarm SPWebServer SPWebApplication SPSite HighBackward Compatibility With WSS v2 Some classes are obsolote -SPGlobalConfig -SPVirtualServer SPWeb SPList SPListItem
SPSite Object • Represents site collection • User 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 objects • Often must use SPSite object to access SPWeb objects
Calling Dispose • Many WSS OM objects follow IDisposable pattern • They use unmanaged resources that must be released • Failure to call Dispose can cause serious memory leakage
SPList and SPListItem • Lists are modeled using SPList objects • Items modeled using SPListItem objects • Document libraries can be accessed using SPList
SPFile and SPFolder • Site represents hierarchy of files and folders • Files 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 object • Can convert SPList to SPDocumentLibrary • Make extra functionality accessible
demo Exploring SharePoint using the Object Model
Security-Related Changes • Impersonatingusing the SPSiteconstructor • ElevatingPrivileges • The ISecurableObject Interface Don’tforget: Test your Web Parts withthe least security permissions!
What’s happening by default? • Web Part code is executed with the account of the logged-on user • Impersonation done by SharePoint • Handle this elegantly!
Impersonating • Constructor of SPSite accepts now an SPUserToken used to impersonate a specific user • Tokens time out after 24 hours • Web Part requires SharePointPermission with Impersonate option
Elevating Permissions • Some aspects of WSS OM require privileged users • Run 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 interface • SPWeb, SPList, SPListItem
demo Better support for security and OM programming
Querying Data with CAML • CAML = Collaborative Application Markup Language • Used in SharePoint for • Definition of the Sites, Lists and Views • Querying of SharePoint content • Executing CAML Queries • SPQuery • SPSiteDataQuery • Lists.asmx
demo Executing CAML Queries
WorkingRemotelywithLists and Documents Remotely view and edit SharePoint List data http://[server]/_vti_bin/Lists.asmx Operations available: Work with Document Libraries using FrontPage RPC
demo An 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 v2 • only possible for document libraries • executed in an asynchronous manner • WSS v3 events architecture significantly improved • Scope 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 scenarios • Custom policies • Features
Creating an Event Handler • .NET class library • Reference to Microsoft.SharePoint.dll • Custom 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 assembly • Deploy 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
demo WSS Event Handlers
New Classes in WSS OM • Navigation • Content Types • Recycle Bin • Versioning • Workflow
Navigation • WSS Navigation is extensible • Add nodes through WSS UI • Adds nodes through code
Content Types • SPContentTypeCollection • SPContentType • SPContentTypeId • SPFieldLinkCollection • SPFieldLink • SPXmlDocumentCollection
SPAudit and SPAuditEntry • WSS provides rich auditing support • But 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
demo New OM Classes
Summary • WSS exposes a veryrichobject model • Don’tforget to clean up your WSS v2 code a bit • And do call Dispose() • Manyimprovements have been done to remove the many issues regardingsecurity and SharePoint programming • Impersonationis more elegant • Common interface for objectsthat support ACL’s • Web Services are yourway of gettingacces to SharePoint remotely • Event handlers are now a major extensibility option • Manymany new classes .. And wait ‘till you’veseen the MOSS objectmodels
Q&A Questions?
Related Content Breakout SessionsSession Codes and Titles • Chalk-TalksSession Codes and Titles • Instructor-led LabsSession Codes and Titles • Hands-on LabsHands-on Lab Codes and Titles
Resources Required slide Technical Communities, Webcasts, Blogs, Chats & User Groups http://www.microsoft.com/communities/default.mspx Microsoft Learning and Certification http://www.microsoft.com/learning/default.mspx Microsoft Developer Network (MSDN) & TechNet http://microsoft.com/msdn http://microsoft.com/technet Trial Software and Virtual Labs http://www.microsoft.com/technet/downloads/trials/default.mspx
Required slide Complete an evaluation on CommNet and enter to win!