SlideShare a Scribd company logo
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 Web Part Framework Server Object Model for programmatic access to SharePoint data We offer functionality as XML web services for access from remote machines
.NET Object Model Managed code object model on the server Accessible via ASP.NET or any other server process Implemented in C# Exposes almost of all of the data stored in WSS
NET Object model Examples of what can be done with the Object Mode: Add, edit, delete, and retrieve data from SharePoint Lists  Create new lists and set list metadata (e.g. the fields in a list)  Set web properties  Work with documents in document libraries.  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!
Example Objects List Data SPField SPFieldCollection SPListCollection SPList SPListItemCollection SPListItem SPView Administration SPGlobalAdmin SPQuota SPVirtualServer Security SPGroup SPGroupCollection SPSite SPUser SPUserCollection Documents SPDocumentLibrary SPFile SPFileCollection SPFolder
ASP.Net Security For content stored in WSS, only registered set of web custom controls will run in pages Inline script in the page will not execute 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
Getting Started with OM Build a web part  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. 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 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 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: http://myweb/_layouts/myapp/mypage.aspx http://myweb/subweb1/_layouts/myapp/mypage.aspx 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 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
Demo Hello World Web Part
Working with the OM The object model has three top-level objects: SPWeb (represents an individual site) SPSite (represents a site collection, which is a set of web sites) SPGlobalAdmin (used for global administration settings) 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 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. Example Properties: Web.Lists (returns a collection of lists) Web.Title (returns the title of 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: SPWeb myweb = SPControl.GetContextWeb(Context);
Demo Showing Web and List Properties
Accessing data in a WSS List Get a SPList or SPDocumentLibrary object. SPList mylist = web.Lists[“Events”]; 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 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 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[&quot;Tasks&quot;]; SPListItemCollection items=tasks.Items; foreach(SPListItem item in items) { output.Write(item[&quot;Title&quot;].ToString() + item[&quot;Status&quot;].ToString() + &quot;<br>&quot;); }
Updating data 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 This helps performance by minimizing SQL queries underneath the covers 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: Example: SPListItem item = items[0]; item[&quot;Status&quot;]=&quot;Not Started&quot;; item[&quot;Title&quot;]=&quot;Task Title&quot;; 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. FormDigest is based on username and site.  It will time out after 30 minutes. Best solution is to include <FormDigest runat=“Server”/> 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.
Adding Users to a web Get the appropriate SPRole object: SPRole admins = web.Roles[&quot;Administrator&quot;]; Call the AddUser method: admins.AddUser(&quot;redmond\\gfoltz&quot;,&quot;Greg@hotmail.com&quot;,&quot;Greg Foltz&quot;,&quot;&quot;);
Demo 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: Bad Example: SPWeb web = SPControl.GetContextWeb(Context); web.Lists[&quot;Tasks&quot;].Title=&quot;mytitle&quot;; web.Lists[&quot;Tasks&quot;].Description=&quot;mydescription&quot;; web.Lists[&quot;Tasks&quot;].Update(); Good Example: SPWeb web = SPControl.GetContextWeb(Context); SPList mylist = web.Lists[&quot;Tasks&quot;]; mylist.Title=&quot;mytitle&quot;; mylist.Description=&quot;mydescription&quot;; mylist.Update();
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. 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. Web Services in WSS
Web Service Methods GetListCollection GetListItems GetWebCollection UpdateList UpdateListItems GetWebInfo GetWebPart GetSmartPageDocument And more…
Getting Started With Web Services Create a Windows Application In Visual Studio, choose ‘Add Web Reference’ Enter  http://<server>/_vti_bin/lists.asmx  to access the lists web service Other services include: UserGroups.asmx – users and groups Webs.asmx – Web information Views.asmx – View information 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: public Lists() { this.Url = &quot;http://mikmort3/_vti_bin/lists.asmx&quot;; this.Credentials=System.Net.CredentialCache.DefaultCredentials; }
Demo Building a Web Service Client
Events We support events on document libraries. Operations such as add, update, delete, check-in, check-out, etc. Events are asynchronous Events call IListEventSink managed interface.  Documentation and Sample in the SDK
Optimizing Performance of OM 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 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) CAML is still used in several places Field Type Definitions Site and List Templates View definitions
SDK Available Documentation about V2 available at  http://msdn.microsoft.com/sharepoint/
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 + &quot;<br>&quot;); } } private void ShowSubWebsWithLists(HtmlTextWriter output) { SPWeb web = SPControl.GetContextWeb(Context); SPWebCollection mywebs = web.Webs; foreach (SPWeb myweb in mywebs) { output.Write(&quot;<b>&quot; + myweb.Title + &quot;<br>&quot; + &quot;</b>&quot;); SPListCollection lists = myweb.Lists; foreach (SPList list in lists) { if (list.ItemCount>10) { output.Write(list.Title + &quot;: &quot; + list.ItemCount + &quot;<br>&quot;); } } } }
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(&quot;Shared Documents&quot;); SPFileCollection myfiles = myfolder.Files; foreach (SPFile file in myfiles) { if (file.Length>(maxsize*1024)) { Response.Write(file.Name + &quot;: &quot; + file.Length/1024 + &quot;kb<br>&quot;); file.CopyTo(&quot;Archive/&quot;+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 email = TextBox3.Text; SPRole admins = web.Roles[&quot;Administrator&quot;]; try  { admins.AddUser(username,email,displayname,&quot;&quot;); Label4.Text=&quot;Successfully added user&quot;; } catch(Exception ex) { Label4.Text=ex.ToString(); } }

More Related Content

What's hot (20)

DOCX
TrainmeSofttech - Selenium Training
Trainme Softtech
 
PPT
Ajax toolkit-framework
WBUTTUTORIALS
 
PPTX
Increase automation to rest
vodQA
 
PPTX
EPiServer Deployment Tips & Tricks
EPiServer Meetup Oslo
 
PPTX
Test automation
Kaushik Banerjee
 
PPTX
Introduction To Building Enterprise Web Application With Spring Mvc
Abdelmonaim Remani
 
PPT
Ajax toolkit framework
Sunil Kumar
 
PPT
Entity frameworks101
Rich Helton
 
PDF
Asp.net state management
priya Nithya
 
PPTX
Web API with ASP.NET MVC by Software development company in india
iFour Institute - Sustainable Learning
 
PDF
Jinal desai .net
rohitkumar1987in
 
PPTX
AWS Atlanta meetup Build Tools - Code Commit, Code Build, Code Deploy
Adam Book
 
PPTX
Spring Basics
ThirupathiReddy Vajjala
 
PPT
Web Application Deployment
elliando dias
 
PPT
Building Cool apps with flex
Joseph Khan
 
PPTX
Android MVVM architecture using Kotlin, Dagger2, LiveData, MediatorLiveData
Waheed Nazir
 
DOCX
Microsoft identity platform and device authorization flow to use azure servic...
Sunil kumar Mohanty
 
PPT
Introduction to Adobe Flex - Zaloni
Joseph Khan
 
PPT
Tumbleweed intro
Rich Helton
 
PPT
Selenium
Purna Chandar
 
TrainmeSofttech - Selenium Training
Trainme Softtech
 
Ajax toolkit-framework
WBUTTUTORIALS
 
Increase automation to rest
vodQA
 
EPiServer Deployment Tips & Tricks
EPiServer Meetup Oslo
 
Test automation
Kaushik Banerjee
 
Introduction To Building Enterprise Web Application With Spring Mvc
Abdelmonaim Remani
 
Ajax toolkit framework
Sunil Kumar
 
Entity frameworks101
Rich Helton
 
Asp.net state management
priya Nithya
 
Web API with ASP.NET MVC by Software development company in india
iFour Institute - Sustainable Learning
 
Jinal desai .net
rohitkumar1987in
 
AWS Atlanta meetup Build Tools - Code Commit, Code Build, Code Deploy
Adam Book
 
Web Application Deployment
elliando dias
 
Building Cool apps with flex
Joseph Khan
 
Android MVVM architecture using Kotlin, Dagger2, LiveData, MediatorLiveData
Waheed Nazir
 
Microsoft identity platform and device authorization flow to use azure servic...
Sunil kumar Mohanty
 
Introduction to Adobe Flex - Zaloni
Joseph Khan
 
Tumbleweed intro
Rich Helton
 
Selenium
Purna Chandar
 

Similar to Wss Object Model (20)

PPTX
SharePoint Object Model, Web Services and Events
Mohan Arumugam
 
PPTX
Share Point Object Model
SharePoint Experts
 
PPTX
Share point development 101
Becky Bertram
 
PPS
SharePoint 2007 Presentation
Ajay Jain
 
PPTX
SharePoint 2010 Application Development Overview
Rob Windsor
 
PPTX
Getting Started with SharePoint Development
Chakkaradeep Chandran
 
PPTX
Developing With Data Technologies
Chakkaradeep Chandran
 
PPTX
Rest API and Client OM for Developer
InnoTech
 
PPT
SharePoint Developer Education Day Palo Alto
llangit
 
PDF
Tutorial, Part 2: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
SPTechCon
 
PPTX
What’s New for Devs
MicrosoftFeed
 
PPTX
SharePoint 2010 developer overview (in Visual Studio 2010)
Mithun T. Dhar
 
PPTX
Help! I've got a share point site! Now What?
Becky Bertram
 
PPTX
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
SharePoint Saturday NY
 
PPTX
SharePoint Development For Asp Net Developers
Corey Roth
 
PPTX
SharePoint 2014: Where to save my data, for devs!
Ben Steinhauser
 
PPTX
SoCalCodeCamp SharePoint Server 2010 a Developer Platform
Ivan Sanders
 
PPTX
What's New for SP2010 Devs
Mohamed Yehia Abdul Kader
 
PPTX
Sharepoint development 2013 course content | sharepoint 2013 course content
Global Online Trainings
 
PPTX
SharePoint Programming Basic
Quang Nguyễn Bá
 
SharePoint Object Model, Web Services and Events
Mohan Arumugam
 
Share Point Object Model
SharePoint Experts
 
Share point development 101
Becky Bertram
 
SharePoint 2007 Presentation
Ajay Jain
 
SharePoint 2010 Application Development Overview
Rob Windsor
 
Getting Started with SharePoint Development
Chakkaradeep Chandran
 
Developing With Data Technologies
Chakkaradeep Chandran
 
Rest API and Client OM for Developer
InnoTech
 
SharePoint Developer Education Day Palo Alto
llangit
 
Tutorial, Part 2: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
SPTechCon
 
What’s New for Devs
MicrosoftFeed
 
SharePoint 2010 developer overview (in Visual Studio 2010)
Mithun T. Dhar
 
Help! I've got a share point site! Now What?
Becky Bertram
 
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
SharePoint Saturday NY
 
SharePoint Development For Asp Net Developers
Corey Roth
 
SharePoint 2014: Where to save my data, for devs!
Ben Steinhauser
 
SoCalCodeCamp SharePoint Server 2010 a Developer Platform
Ivan Sanders
 
What's New for SP2010 Devs
Mohamed Yehia Abdul Kader
 
Sharepoint development 2013 course content | sharepoint 2013 course content
Global Online Trainings
 
SharePoint Programming Basic
Quang Nguyễn Bá
 
Ad

More from maddinapudi (12)

PPT
Enterprise Content Management
maddinapudi
 
DOCX
eRoom Installation Screen Shots
maddinapudi
 
PDF
eRoom 7 Installation,Upgrade, and Configuration Guide
maddinapudi
 
PPT
Vs2008 to improve Development
maddinapudi
 
PPT
WSS 3.0 using asp.net 2.0 for extending pages,Server Farms etc..
maddinapudi
 
PPT
SharePoint Web Parts
maddinapudi
 
PDF
Dotnet Interview Questions
maddinapudi
 
PDF
White Paper On Moss 2007
maddinapudi
 
PDF
Asp.Net MVC Framework Design Pattern
maddinapudi
 
PDF
Connected Applications using WF and WCF
maddinapudi
 
PDF
.net 3.5 and vs 2008
maddinapudi
 
PDF
Introduction to Asp.net 3.5 using VS 2008
maddinapudi
 
Enterprise Content Management
maddinapudi
 
eRoom Installation Screen Shots
maddinapudi
 
eRoom 7 Installation,Upgrade, and Configuration Guide
maddinapudi
 
Vs2008 to improve Development
maddinapudi
 
WSS 3.0 using asp.net 2.0 for extending pages,Server Farms etc..
maddinapudi
 
SharePoint Web Parts
maddinapudi
 
Dotnet Interview Questions
maddinapudi
 
White Paper On Moss 2007
maddinapudi
 
Asp.Net MVC Framework Design Pattern
maddinapudi
 
Connected Applications using WF and WCF
maddinapudi
 
.net 3.5 and vs 2008
maddinapudi
 
Introduction to Asp.net 3.5 using VS 2008
maddinapudi
 
Ad

Recently uploaded (20)

PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PPTX
Farrell_Programming Logic and Design slides_10e_ch02_PowerPoint.pptx
bashnahara11
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
RAT Builders - How to Catch Them All [DeepSec 2024]
malmoeb
 
PDF
Per Axbom: The spectacular lies of maps
Nexer Digital
 
PPTX
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PPTX
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
Farrell_Programming Logic and Design slides_10e_ch02_PowerPoint.pptx
bashnahara11
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
RAT Builders - How to Catch Them All [DeepSec 2024]
malmoeb
 
Per Axbom: The spectacular lies of maps
Nexer Digital
 
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 

Wss Object Model

  • 1. Programming SharePoint Object Model, Web Services, and Events Michael Morton 4/15/03
  • 2. Summary of .NET support SharePoint will use ASP.NET instead of ISAPI for base page execution Web Part Framework Server Object Model for programmatic access to SharePoint data We offer functionality as XML web services for access from remote machines
  • 3. .NET Object Model Managed code object model on the server Accessible via ASP.NET or any other server process Implemented in C# Exposes almost of all of the data stored in WSS
  • 4. NET Object model Examples of what can be done with the Object Mode: Add, edit, delete, and retrieve data from SharePoint Lists Create new lists and set list metadata (e.g. the fields in a list) Set web properties Work with documents in document libraries. 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!
  • 5. Example Objects List Data SPField SPFieldCollection SPListCollection SPList SPListItemCollection SPListItem SPView Administration SPGlobalAdmin SPQuota SPVirtualServer Security SPGroup SPGroupCollection SPSite SPUser SPUserCollection Documents SPDocumentLibrary SPFile SPFileCollection SPFolder
  • 6. ASP.Net Security For content stored in WSS, only registered set of web custom controls will run in pages Inline script in the page will not execute 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
  • 7. Getting Started with OM Build a web part 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. Web Part is reusable and can be managed using all of the web part tools and UI.
  • 8. Getting Started with the OM Build an ASPX page 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 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: http://myweb/_layouts/myapp/mypage.aspx http://myweb/subweb1/_layouts/myapp/mypage.aspx ASPX page will run using the context of the web under which it is running.
  • 9. Getting Started with the OM 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 For example, you could build a command-line utility to perform certain actions
  • 10. Demo Hello World Web Part
  • 11. Working with the OM The object model has three top-level objects: SPWeb (represents an individual site) SPSite (represents a site collection, which is a set of web sites) SPGlobalAdmin (used for global administration settings) In order to perform actions on data within a web, you must first get an SPWeb object.
  • 12. Adding our namespace You should add references to the WSS namespaces to your source files using Microsoft.SharePoint; using Microsoft.SharePoint.WebControls; using Microsoft.SharePoint.Administration; …
  • 13. Key Object – SPWeb Starting point to get at the Lists, Items, Documents, Users, Alerts, etc. for a web site. Example Properties: Web.Lists (returns a collection of lists) Web.Title (returns the title of 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: SPWeb myweb = SPControl.GetContextWeb(Context);
  • 14. Demo Showing Web and List Properties
  • 15. Accessing data in a WSS List Get a SPList or SPDocumentLibrary object. SPList mylist = web.Lists[“Events”]; 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 SPListItemCollection items = mylist.GetItems(query);
  • 16. Accessing data in a list To get data for a field, specify the field name in the indexer for an SPListItem foreach(SPListItem item in items) { Response.Write(item[&quot;Due Date&quot;].ToString()); Response.Write(item[&quot;Status&quot;].ToString()); Response.WRite(item[&quot;Title&quot;].ToString()); }
  • 17. Full Example SPWeb web = SPControl.GetContextWeb(Context); SPList tasks = web.Lists[&quot;Tasks&quot;]; SPListItemCollection items=tasks.Items; foreach(SPListItem item in items) { output.Write(item[&quot;Title&quot;].ToString() + item[&quot;Status&quot;].ToString() + &quot;<br>&quot;); }
  • 18. Updating data 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 This helps performance by minimizing SQL queries underneath the covers Example: SPList mylist = web.Lists[“Tasks”]; mylist.Title=“Tasks!!!”; mylist.Description=“Description!!”; Mylist.Update();
  • 19. Updating List Data SPListItem is another example of an object where you need to call update: Example: SPListItem item = items[0]; item[&quot;Status&quot;]=&quot;Not Started&quot;; item[&quot;Title&quot;]=&quot;Task Title&quot;; item.Update();
  • 20. 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. FormDigest is based on username and site. It will time out after 30 minutes. Best solution is to include <FormDigest runat=“Server”/> 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.
  • 21. Adding Users to a web Get the appropriate SPRole object: SPRole admins = web.Roles[&quot;Administrator&quot;]; Call the AddUser method: admins.AddUser(&quot;redmond\\gfoltz&quot;,&quot;[email protected]&quot;,&quot;Greg Foltz&quot;,&quot;&quot;);
  • 22. Demo Adding users to the site via the OM
  • 23. Keep objects around If you create and destroy objects frequently, you may do extra SQL queries and have code that is incorrect: Bad Example: SPWeb web = SPControl.GetContextWeb(Context); web.Lists[&quot;Tasks&quot;].Title=&quot;mytitle&quot;; web.Lists[&quot;Tasks&quot;].Description=&quot;mydescription&quot;; web.Lists[&quot;Tasks&quot;].Update(); Good Example: SPWeb web = SPControl.GetContextWeb(Context); SPList mylist = web.Lists[&quot;Tasks&quot;]; mylist.Title=&quot;mytitle&quot;; mylist.Description=&quot;mydescription&quot;; mylist.Update();
  • 24. 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. 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. Web Services in WSS
  • 25. Web Service Methods GetListCollection GetListItems GetWebCollection UpdateList UpdateListItems GetWebInfo GetWebPart GetSmartPageDocument And more…
  • 26. Getting Started With Web Services Create a Windows Application In Visual Studio, choose ‘Add Web Reference’ Enter http://<server>/_vti_bin/lists.asmx to access the lists web service Other services include: UserGroups.asmx – users and groups Webs.asmx – Web information Views.asmx – View information Subscription.asmx – Subscriptions
  • 27. 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: public Lists() { this.Url = &quot;http://mikmort3/_vti_bin/lists.asmx&quot;; this.Credentials=System.Net.CredentialCache.DefaultCredentials; }
  • 28. Demo Building a Web Service Client
  • 29. Events We support events on document libraries. Operations such as add, update, delete, check-in, check-out, etc. Events are asynchronous Events call IListEventSink managed interface. Documentation and Sample in the SDK
  • 30. Optimizing Performance of OM 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 Minimizing managed/unmanaged transitions also a goal, though this is mostly taken care within the OM.
  • 31. What about CAML? Page Execution will no longer be driven by CAML (XML schema used in SharePoint) CAML is still used in several places Field Type Definitions Site and List Templates View definitions
  • 32. SDK Available Documentation about V2 available at http://msdn.microsoft.com/sharepoint/
  • 34.  
  • 35. 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 + &quot;<br>&quot;); } } private void ShowSubWebsWithLists(HtmlTextWriter output) { SPWeb web = SPControl.GetContextWeb(Context); SPWebCollection mywebs = web.Webs; foreach (SPWeb myweb in mywebs) { output.Write(&quot;<b>&quot; + myweb.Title + &quot;<br>&quot; + &quot;</b>&quot;); SPListCollection lists = myweb.Lists; foreach (SPList list in lists) { if (list.ItemCount>10) { output.Write(list.Title + &quot;: &quot; + list.ItemCount + &quot;<br>&quot;); } } } }
  • 36. 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(&quot;Shared Documents&quot;); SPFileCollection myfiles = myfolder.Files; foreach (SPFile file in myfiles) { if (file.Length>(maxsize*1024)) { Response.Write(file.Name + &quot;: &quot; + file.Length/1024 + &quot;kb<br>&quot;); file.CopyTo(&quot;Archive/&quot;+file.Name,true); } } }
  • 37. 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 email = TextBox3.Text; SPRole admins = web.Roles[&quot;Administrator&quot;]; try { admins.AddUser(username,email,displayname,&quot;&quot;); Label4.Text=&quot;Successfully added user&quot;; } catch(Exception ex) { Label4.Text=ex.ToString(); } }