Home > Back to basics, SharePoint 2010 > SharePoint Object Model 101

SharePoint Object Model 101

It is important to familiarize yourself with SharePoint Object Model as a SharePoint developer. This is a back to basics post about SharePoint Object model on the server side; in the next post I will introduce the SharePoint client side object model 101.
1. Retrieve all webs from site collections

using (SPSite site = new SPSite("http://YBBEST"))
 {
 foreach (SPWeb web in site.AllWebs)
 {
 Console.WriteLine("SPWeb title: "+web.Title);
 }
 }

2. Loop through all lists within the web

using (SPSite site = new SPSite("http://YBBEST"))
 {

using (SPWeb web = site.OpenWeb())
 {
 foreach (SPList spList in web.Lists)
 {
 Console.WriteLine(spList.Title);
 }
 }
 }

3. Different between AvailableFields and Fields.The Fields collection contains the all site columns in the current site while AvailableFields collection contains all site columns that can be used in the current site. (It includes site columns in the current site and its parent site).The Field in the AvailableFields collection is read-only and you cannot modify it while you can modify the Field in the Fields collection.

4. Get Item Field Value

using (SPSite site = new SPSite("http://YBBEST"))
 {
 using (SPWeb web = site.OpenWeb())
 {
 SPList spList = web.Lists.TryGetList("Tasks");
 if (spList != null)
 {
 Console.WriteLine("Success!");
 Console.WriteLine(string.Format("Title : {0}", spList.Title));
 Console.WriteLine(string.Format("Task Status : {0}", spList.Items[0]["Status"]));
 }
 else
 {
 Console.WriteLine("List does not exist !");
 }
 }
 }

5.Using console application to call SharePoint web services.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: