Programming SharePoint Object Model, Web Services, and Events Michael Morton 4/15/03.

Slides:



Advertisements
Similar presentations
Site Collection, Sites and Sub-sites
Advertisements

June 4-8 Orlando. WSS Object Model Fundamentals Working Remotely with Lists and Document Libraries Cross-Site Data Queries Exploring New WSS Classes.
Microsoft Office SharePoint Portal Server 2007 Introduction to InfoPath Forms Services Daryl L. Rudolph.
Designing, Deploying and Managing Workflow in SharePoint Sites Steve Heaney Product Development Manager OBS
Forms Authentication, Users, Roles, Membership Ventsislav Popov Crossroad Ltd.
Developing for SharePoint with Visual Studio Jason Keicher
Randy Williams, MOSS MVP Senior Consultant Synergy Corporate Technologies.
DEV392: Extending SharePoint Products And Technologies Through Web Parts And ASP.NET Clint Covington, Program Manager Data And Developer Services - Office.
Michael Donovan, River Campus Libraries – 12/03 DocuShare Overview and Training.
27. to 28. March 2007 | Geneva, Switzerland. Fabrice Romelard ilem SA Level 200.
St. Louis Day of Dot Net 2011 Jump Start: SharePoint Development Becky Bertram Independent SharePoint Consultant SharePoint MVP, MCSD.NET, MCTS
Becky Bertram SharePoint MVP
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
Windows SharePoint Services 3.0 (WSS v3) Browser Clients MS Word Clients MS Outlook Clients Microsoft Office SharePoint Server 2007 (MOSS) Windows.
Sharepoint Portal Server Basics. Introduction Sharepoint server belongs to Microsoft family of servers Integrated suite of server capabilities Hosted.
Enterprise Reporting with Reporting Services SQL Server 2005 Donald Farmer Group Program Manager Microsoft Corporation.
AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem MVP SharePoint Portal.
WSS 3.0 Architecture and Enhancements Ashvini Shahane Member – Synergetics Research Lab.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
An Introduction to ASP.NET Ed Dunhill blogs.msdn.com/edunhill SLIDE7.
Forms Authentication, Users, Roles, Membership Svetlin Nakov Telerik Corporation
Workflow and SharePoint Presented by Ben Geers. Overview What is workflow? Windows Workflow Foundation How does workflow apply to SharePoint? WSS v3 vs.
OBJECT REFERENCE. Objective How to work with objects in SharePoint by using classes?
Virtual techdays INDIA │ 9-11 February 2011 SharePoint Foundation: The journey from Windows SharePoint Services Hari Seelam & Raju Upadhyayula │ Solution.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Basic Developer Knowledge That Every SharePoint Admin Must Have Randy Williams, MVP MOSS Synergy Corporate Technologies
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Workflow Development Overview Architecture Requirements Types of workflows Stages of workflow.
Microsoft SharePoint Server 2010 for the Microsoft ASP.NET Developer Yaroslav Pentsarskyy
HOW SHAREPOINT WORKS By Gary Newman. Root Folder Virtual Directories SP Farm DNS Iterative Forward DNS query for A host record HTTP request HTML & JS.
Searching Business Data with MOSS 2007 Enterprise Search Presenter: Corey Roth Enterprise Consultant Stonebridge Blog:
Slide 1.NET Development for Project 2003 Samples from the Project 2003 SDK Jim Corbin Programmer Writer Office Developer Documentation Microsoft Corporation.
What’s new in Kentico CMS 5.0 Michal Neuwirth Product Manager Kentico Software.
New & Improved Events List Relationships and Joins Large List Support Field & List Item Validation.
James Akrigg Microsoft Ltd Integrating InfoPath Forms Into Workflow Solutions And Business Processes.
Module 7 : Configuration I Jong S. Bok
Office Business Applications Workshop Defining Business Process and Workflows.
Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. SharePoint API and Development in ASP.NET Creating “Hello World” application Working with.
VITALE, CATURANO & COMPANY LTD Microsoft SharePoint Web Part Development Overview VITALE, CATURANO & COMPANY LTD SharePoint Developer Series – Web Part.
Solutions using Microsoft Content Management Server 2002 Connector for SharePoint Technologies Sue Corke Mark Harrison Microsoft UK.
Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Search Overview Search Features: WSS and Office Search Architecture Content Sources and.
What’s New in SharePoint 2010 SharePoint 2010 Development Primer New Developer Tools for SharePoint 2010 SharePoint 2010 Integration with PowerShell.
1 © Xchanging 2010 no part of this document may be circulated, quoted or reproduced without prior written approval of Xchanging. MOSS Training – UI customization.
Coding Compliance Components Writing Custom Policies for Auditing, Expiration and More Jason Morrill Program Manager Windows SharePoint Services.
Microsoft SharePoint Server 2007 Technical Overview Romeo Pruno nonaka.eu.
Windows Sharepoint Services , Tracking, And Other Collaboration Applications Mike Ormond Developer & Platform Group, Microsoft Ltd
Microsoft Visual Studio 2005 Tools for the Office System: Building Office Solutions Using Visual Studio 2005 Tools for Office Andrew Coates Developer Evangelist.
Extending SharePoint through Web Parts and ASP.NET 최승현 대리 한국마이크로소프트.
NET Development on Microsoft SharePoint Technology Part 4: Templates, Features, and Solution Deployment Mick Badran Breeze Training Consulting Trainer.
Application Hosting and Customization Introducing Sandboxed Solutions Executing Code in the Sandbox Sandbox Resource Monitoring.
Windows SharePoint Services Development Part 1: Paul Appleby Application Architect Microsoft Limited.
Programming the Microsoft SharePoint Products and Technologies Object Model Paul Appleby Developer & Platform Group
11 User Controls Beginning ASP.NET in C# and VB Chapter 8.
The 2007 Microsoft Office System Servers Enterprise Content Management, Workflow and Forms Martin Parry Developer and Platform Group, Microsoft Ltd
Programming the Microsoft SharePoint Products and Technologies Object Model Paul Appleby Developer & Platform Group
VITALE, CATURANO & COMPANY LTD Microsoft SharePoint Architecture & Object Model Overview VITALE, CATURANO & COMPANY LTD SharePoint Developer Series – Architecture.
Workflow in Microsoft Office SharePoint Server Jessica Gruber Consultant Microsoft Corporation.
Developer Exam Preparation Thom Robbins Bryan Soltis
DEVELOPING MICROSOFT SHAREPOINT SERVER 2013 CORE SOLUTIONS Microsoft Exam Study Material Sponsored By:
Excel Services Displays all or parts of interactive Excel worksheets in the browser –Excel “publish” feature with optional parameters defined in worksheet.
Powering up your Office 365 cmdlets with CSOM Bjoern H Rapp, Senior Architect Public Cloud, SopraSteria.
St. Louis Day of Dot Net 2011 Jump Start: SharePoint Development
Building Dynamic Applications with the SharePoint Client Object Model
Programming SharePoint Object Model, Web Services, and Events
Searching Business Data with MOSS 2007 Enterprise Search
Microsoft Dynamics.
Searching Business Data with MOSS 2007 Enterprise Search
SharePoint Object Model
Mike Ammerlaan Program Manager Microsoft Corporation
MS Confidential : SharePoint 2010 Developer Workshop (Beta1)
Presentation transcript:

Programming SharePoint Object Model, Web Services, and Events Michael Morton 4/15/03

Summary of.NET support SharePoint will use ASP.NET instead of ISAPI for base page execution SharePoint will use ASP.NET instead of ISAPI for base page execution Web Part Framework Web Part Framework Server Object Model for programmatic access to SharePoint data Server Object Model for programmatic access to SharePoint data We offer functionality as XML web services for access from remote machines We offer functionality as XML web services for access from remote machines

.NET Object Model Managed code object model on the server Managed code object model on the server Accessible via ASP.NET or any other server process Accessible via ASP.NET or any other server process Implemented in C# Implemented in C# Exposes almost of all of the data stored in WSS Exposes almost of all of the data stored in WSS

NET Object model Examples of what can be done with the Object Mode: Examples of what can be done with the Object Mode: Add, edit, delete, and retrieve data from SharePoint Lists Add, edit, delete, and retrieve data from SharePoint Lists Create new lists and set list metadata (e.g. the fields in a list) Create new lists and set list metadata (e.g. the fields in a list) Set web properties Set web properties Work with documents in document libraries. Work with documents in document libraries. Perform administrative tasks such as creating webs, adding users, creating roles, etc. Perform administrative tasks such as creating webs, adding users, creating roles, etc. Pretty much any functionality in the UI can be automated through the OM! Pretty much any functionality in the UI can be automated through the OM!

Example Objects List Data List Data SPField SPField SPFieldCollection SPFieldCollection SPListCollection SPListCollection SPList SPList SPListItemCollection SPListItemCollection SPListItem SPListItem SPView SPView Administration Administration SPGlobalAdmin SPGlobalAdmin SPQuota SPQuota SPVirtualServer SPVirtualServer Security Security SPGroup SPGroup SPGroupCollection SPGroupCollection SPSite SPSite SPUser SPUser SPUserCollection SPUserCollection Documents Documents SPDocumentLibrary SPDocumentLibrary SPFile SPFile SPFileCollection SPFileCollection SPFolder SPFolder

ASP.Net Security For content stored in WSS, only registered set of web custom controls will run in pages For content stored in WSS, only registered set of web custom controls will run in pages Inline script in the page will not execute Inline script in the page will not execute Code behind in pages can be made to work Code behind in pages can be made to work All Executable code (e.g. web custom controls, web parts, and code-behind classes) needs to be installed on physical web server All Executable code (e.g. web custom controls, web parts, and code-behind classes) needs to be installed on physical web server

Getting Started with OM Build a web part Build a web part This is the best option to write code that functions are part of a WSS site or solution This is the best option to write code that functions are part of a WSS site or solution There will be lots of documentation with the beta on how to build a web part. There will be lots of documentation with the beta on how to build a web part. Web Part is reusable and can be managed using all of the web part tools and UI. Web Part is reusable and can be managed using all of the web part tools and UI.

Getting Started with the OM Build an ASPX page Build an ASPX page Code cannot live inline in a page within the site. Code cannot live inline in a page within the site. Creating pages underneath the /_layouts directory is often the best option for custom ASPX apps on top of SharePoint Creating pages underneath the /_layouts directory is often the best option for custom ASPX apps on top of SharePoint This lets your page be accessible from any web. For example, if you build mypage.aspx in _Layouts, it is accessible from the following URLs: This lets your page be accessible from any web. For example, if you build mypage.aspx in _Layouts, it is accessible from the following URLs: ASPX page will run using the context of the web under which it is running. ASPX page will run using the context of the web under which it is running.

Getting Started with the OM Windows Executable or any other application Windows Executable or any other application Object model can be called from pretty much any code context. It is not limited to just web parts or ASP.Net Object model can be called from pretty much any code context. It is not limited to just web parts or ASP.Net For example, you could build a command- line utility to perform certain actions For example, you could build a command- line utility to perform certain actions

Demo Hello World Web Part Hello World Web Part

Working with the OM The object model has three top-level objects: The object model has three top-level objects: SPWeb (represents an individual site) SPWeb (represents an individual site) SPSite (represents a site collection, which is a set of web sites) SPSite (represents a site collection, which is a set of web sites) SPGlobalAdmin (used for global administration settings) SPGlobalAdmin (used for global administration settings) In order to perform actions on data within a web, you must first get an SPWeb object. In order to perform actions on data within a web, you must first get an SPWeb object.

Adding our namespace You should add references to the WSS namespaces to your source files You should add references to the WSS namespaces to your source files using Microsoft.SharePoint; using Microsoft.SharePoint.WebControls; using Microsoft.SharePoint.Administration; …

Key Object – SPWeb Starting point to get at the Lists, Items, Documents, Users, Alerts, etc. for a web site. Starting point to get at the Lists, Items, Documents, Users, Alerts, etc. for a web site. Example Properties: Example Properties: Web.Lists (returns a collection of lists) Web.Lists (returns a collection of lists) Web.Title (returns the title of the site) Web.Title (returns the title of the site) Web.Users (returns the users on the site) Web.Users (returns the users on the site) In a web part or ASPX page, you can use the following line to get a SPWeb: In a web part or ASPX page, you can use the following line to get a SPWeb: SPWeb myweb = SPControl.GetContextWeb(Context);

Demo Showing Web and List Properties Showing Web and List Properties

Accessing data in a WSS List Get a SPList or SPDocumentLibrary object. Get a SPList or SPDocumentLibrary object. SPList mylist = web.Lists[“Events”]; You can then call the.Items property to get all of the items: You can then call the.Items property to get all of the items: SPListItemCollection items = mylist.Items; If you only want a subset of the items, call the GetItems method and pass a SPQuery object If you only want a subset of the items, call the GetItems method and pass a SPQuery object SPListItemCollection items = mylist.GetItems(query);

Accessing data in a list To get data for a field, specify the field name in the indexer for an SPListItem To get data for a field, specify the field name in the indexer for an SPListItem foreach(SPListItem item in items) { Response.Write(item["Due Date"].ToString()); Response.Write(item["Status"].ToString());Response.WRite(item["Title"].ToString());}

Full Example SPWeb web = SPControl.GetContextWeb(Context); SPList tasks = web.Lists["Tasks"]; SPListItemCollection items=tasks.Items; foreach(SPListItem item in items) { output.Write(item["Title"].ToString() + item["Status"].ToString() + " "); }

Updating data Most objects in WSS do not immediately update data when you change a property Most objects in WSS do not immediately update data when you change a property You need to first call the Update() method on the object You need to first call the Update() method on the object This helps performance by minimizing SQL queries underneath the covers This helps performance by minimizing SQL queries underneath the covers Example: Example: SPList mylist = web.Lists[“Tasks”]; mylist.Title=“Tasks!!!”;mylist.Description=“Description!!”;Mylist.Update();

Updating List Data SPListItem is another example of an object where you need to call update: SPListItem is another example of an object where you need to call update: Example: Example: SPListItem item = items[0]; item["Status"]="Not Started"; item["Title"]="Task Title"; item.Update();

FormDigest Security By default, the object model will not allow data updates if the form submitting the data does not contain the ‘FormDigest’ security key. By default, the object model will not allow data updates if the form submitting the data does not contain the ‘FormDigest’ security key. FormDigest is based on username and site. It will time out after 30 minutes. FormDigest is based on username and site. It will time out after 30 minutes. Best solution is to include web folder control in ASPX page. Best solution is to include web folder control in ASPX page. If you do not need the security the FormDigest provides, you can set to SPWeb.AllowUnsafeUpdates to bypass this check. If you do not need the security the FormDigest provides, you can set to SPWeb.AllowUnsafeUpdates to bypass this check.

Adding Users to a web Get the appropriate SPRole object: Get the appropriate SPRole object: SPRole admins = web.Roles["Administrator"]; Call the AddUser method: Call the AddUser method: ","Greg Foltz","");

Demo Adding users to the site via the OM Adding users to the site via the OM

Keep objects around If you create and destroy objects frequently, you may do extra SQL queries and have code that is incorrect: If you create and destroy objects frequently, you may do extra SQL queries and have code that is incorrect: Bad Example: Bad Example: SPWeb web = SPControl.GetContextWeb(Context); web.Lists["Tasks"].Title="mytitle";web.Lists["Tasks"].Description="mydescription";web.Lists["Tasks"].Update(); Good Example: Good Example: SPWeb web = SPControl.GetContextWeb(Context); SPList mylist = web.Lists["Tasks"]; mylist.Title="mytitle";mylist.Description="mydescription";mylist.Update();

SharePoint will have web services APIs for accessing content. The web services layer will be built on top of the server OM. SharePoint will have web services APIs for accessing content. The web services layer will be built on top of the server OM. Allows manipulation of Lists, Webs, Views, List Items, etc. Allows manipulation of Lists, Webs, Views, List Items, etc. Functionality will be similar to server object model, but with fewer interfaces optimized to minimize transactions. Functionality will be similar to server object model, but with fewer interfaces optimized to minimize transactions. Office11 (e.g. Excel, DataSheet, Work, Outlook, FrontPage, etc) use web services to access data from WSS. Office11 (e.g. Excel, DataSheet, Work, Outlook, FrontPage, etc) use web services to access data from WSS. Web Services in WSS

Web Service Methods GetListCollection GetListCollection GetListItems GetListItems GetWebCollection GetWebCollection UpdateList UpdateList UpdateListItems UpdateListItems GetWebInfo GetWebInfo GetWebPart GetWebPart GetSmartPageDocument GetSmartPageDocument And more… And more…

Getting Started With Web Services Create a Windows Application Create a Windows Application In Visual Studio, choose ‘Add Web Reference’ In Visual Studio, choose ‘Add Web Reference’ Enter /_vti_bin/lists.asmx to access the lists web service Enter /_vti_bin/lists.asmx to access the lists web servicehttp:// /_vti_bin/lists.asmx Other services include: Other services include: UserGroups.asmx – users and groups UserGroups.asmx – users and groups Webs.asmx – Web information Webs.asmx – Web information Views.asmx – View information Views.asmx – View information Subscription.asmx – Subscriptions Subscription.asmx – Subscriptions

Getting Started with Web Services To send the logged on users’ credentials from the client, add the following line in the web reference object’s constructor: To send the logged on users’ credentials from the client, add the following line in the web reference object’s constructor: public Lists() { public Lists() { this.Url = " this.Url = " this.Credentials=System.Net.CredentialCache.Def aultCredentials; }

Demo Building a Web Service Client Building a Web Service Client

Events We support events on document libraries. We support events on document libraries. Operations such as add, update, delete, check-in, check-out, etc. Operations such as add, update, delete, check-in, check-out, etc. Events are asynchronous Events are asynchronous Events call IListEventSink managed interface. Events call IListEventSink managed interface. Documentation and Sample in the SDK Documentation and Sample in the SDK

Optimizing Performance of OM The biggest goal is to minimize the number of SQL queries. The biggest goal is to minimize the number of SQL queries. It may be helpful to use the SQL profiler to monitor what the OM is doing underneath the covers It may be helpful to use the SQL profiler to monitor what the OM is doing underneath the covers Minimizing managed/unmanaged transitions also a goal, though this is mostly taken care within the OM. Minimizing managed/unmanaged transitions also a goal, though this is mostly taken care within the OM.

What about CAML? Page Execution will no longer be driven by CAML (XML schema used in SharePoint) Page Execution will no longer be driven by CAML (XML schema used in SharePoint) CAML is still used in several places CAML is still used in several places Field Type Definitions Field Type Definitions Site and List Templates Site and List Templates View definitions View definitions

SDK Available Documentation about V2 available at Documentation about V2 available at

Questions?

Code Example -- Enumerate Lists and Webs private void ShowSubWebs(HtmlTextWriter output) { SPWeb web = SPControl.GetContextWeb(Context); SPWebCollection mywebs = web.Webs; foreach (SPWeb myweb in mywebs) { output.Write(myweb.Title + " "); }} private void ShowSubWebsWithLists(HtmlTextWriter output) { SPWeb web = SPControl.GetContextWeb(Context); SPWebCollection mywebs = web.Webs; foreach (SPWeb myweb in mywebs) { output.Write(" " + myweb.Title + " " + " "); SPListCollection lists = myweb.Lists; foreach (SPList list in lists) { if (list.ItemCount>10) { output.Write(list.Title + ": " + list.ItemCount + " "); }}}}

Code Snippet – Copy Files private SPWeb web; private void Page_Load(object sender, System.EventArgs e) { web = SPControl.GetContextWeb(Context); } private void Button1_Click(object sender, System.EventArgs e) { int maxsize = Convert.ToInt32(TextBox1.Text); SPFolder myfolder=web.GetFolder("Shared Documents"); SPFileCollection myfiles = myfolder.Files; foreach (SPFile file in myfiles) { if (file.Length>(maxsize*1024)) { Response.Write(file.Name + ": " + file.Length/ "kb "); file.CopyTo("Archive/"+file.Name,true);}}}

Code Snippet – Add users private void Button1_Click(object sender, System.EventArgs e) { SPWeb web = SPControl.GetContextWeb(Context); string username = TextBox1.Text; string displayname = TextBox2.Text; string = TextBox3.Text; SPRole admins = web.Roles["Administrator"]; try{admins.AddUser(username, ,displayname,""); Label4.Text="Successfully added user"; } catch(Exception ex) {Label4.Text=ex.ToString();}}