Apr 9, 2009

SharePoint Object Model - From SPFarm to SPListItem

In a layer model ASP.NET builds the UI Layer (and also the service facade), the SharePoint Object Model is the business layer and for sure there is also a data access layer. The data access layer is the dark side of SharePoint, because it’s mainly unmanaged. It’s a mixture of unmanaged code and T-SQL. Unfortunately the unmanaged part isn’t under the control of the developer and vulnerable for memory leaks. What you can do is query (only read!) the database with SQL directly, but isn’t that intuitive and not recommended. There are unverified stories that with SharePoint 14 there will be a one to one relation between SharePoint lists and database tables – we will see. To cut a long story short, the way of choice to interact with the SharePoint database is the object model.

The SharePoint object model is simply a beauty. I felt in love with it since I used it the first time about 6 years ago.


SharePoint Object Hierarchy Overview

image

 

Example – From Farm to List Item

Here is an example for beginners how to traverse from SPFarm to SPListItem. The objects used in this example can be found in two namespaces. From SPFarm to SPWebApplication in Microsoft.SharePoint.Administratation, from SPSite to SPListItem in Microsoft.SharePoint. The Namespaces resides both in the Microsoft.SharePoint.dll at “%commonprogramfiles%\Microsoft Shared\web server extensions\12\ISAPI”. Any clue where you will find it in SharePoint 14 ;-)

Always keep in mind that the object model is not remotable and have to run on the SharePoint server!

Console.ForegroundColor = ConsoleColor.Green;
Console.BufferHeight = 1000;

//Get local farm
SPFarm farm = SPFarm.Local;
Console.Write(farm.Id.ToString("N").ToLower());

//loop Services
foreach (SPService service in farm.Services)
{
//find WebService
if (service is SPWebService)
{
SPWebService webService = (SPWebService)service;

//Loop WebApps
foreach (SPWebApplication webApp in webService.WebApplications)
{
Console.Write(webApp.Id.ToString("N").ToLower());

//Loop Site Collections
foreach (SPSite site in webApp.Sites)
{
Console.Write(site.ID.ToString("N").ToLower());

//Loop Sites
foreach (SPWeb web in site.AllWebs)
{
Console.Write(web.ID.ToString("N").ToLower());

//Loop Lists
foreach (SPList list in web.Lists)
{
Console.Write(list.ID.ToString("N").ToLower());

//Loop Items
foreach (SPListItem item in list.Items)
{
Console.Write(item.UniqueId.ToString("N").ToLower());
}
}
web.Dispose();
}
site.Dispose();
}
}

}
}


If you will run it, it will run and run and run and look like this: image I call it the SharePoint Matrix ;-)

24 comments:

Aravind said...

The Microsoft.SharePoint.dll for ShrePoint 2010 is present in C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI

Reuben Gray said...

To create a SharePoint matrix this should be done but what about to get rid of it? I know about ASP.NET but completely new to SharePoint, so would be great help.

K Sarah said...
This comment has been removed by the author.
Xj Cheng said...

When one checks out the altered models of cartier replica Swiss replica watches that are accessible in the market,they will be amazed.Just anticipate about any accounted cast of Swiss watch and you can be abiding that there is a Swiss replica watches accessible in that archetypal too.Yes,do not apprehend your Swiss replica watches to accommodate absolute adornment or accept replica watches uk a case fabricated of gold.For that you charge to acquirement the absolute stuff,but contrarily Swiss replica watches serve the purpose fine.The craftsmen who actualize these Swiss replica watches use the aforementioned machineries that are acclimated for accomplishment the aboriginal ones,appropriately the superior is unsurpassed.A few years back,these watches were not so accepted because they did not advance the actual time.What is alluring a ample amount of barter to chanel replica replica shoes is their availability.A seek on the internet reveals sites that accord with specific appearance houses handbags.You can seek for replica handbags by designer.Spending beneath than two hundred dollars to get a replica backpack appeals to a amount of women.Therefore,the replica handbags business flourishes.Women who dior replica cannot allow or do not wish to absorb a baby affluence on a backpack can now buy a dozen louis vuitton replica.In all honesty,if a woman is walking down the artery with a 18-carat artist backpack or a replica handbag,who can acquaint the difference? Hardly anyone!Analysis out the advanced ambit of louis vuitton replica They do not amount the apple and a lot of gucci replica humans can calmly allow added than one.If you so want,you can accept added than a dozen of them and yet do not feel the pinch.Some humans are accounted to accept added than a dozen models of louis vuitton replica these louis vuitton replica with them.

electronic signature pad said...

Fancy coming across this post almost 5 years later when looking for a solution to the same issues.
Keep the "ILove SharePoint" coming, my friend.

swiss replica watches said...

On a party or possibly a party, every individual would surely notice what we really are donning. Can the idea be Prada and also Armani? Parallels many of us want for you to catch enchantment at each celebration. Formerly, there were just one or two well-liked brands available. They'd their unique or probably signature types the crooks to be renowned for. As a result, the specialized class have been the individual who replica Swiss Valjoux 7750 watches used for you to wear these kind of artist fake Breitling watches issues. It ended up considered a new standing impression, due on the fake Omega Watches fact developer things are actually thus high priced which an ordinary individual are unable to afford the idea. Right currently, people employ designer merchandise denoting significant reputation and also real specialized. Commercialism has replica MontBlanc watches built people for that reason materialistic they will would commit profoundly with replica designer handbags regards to merely a bit of a developer item. Otherwise, they probably have obtained to produce with a similar sum of cash.

Hug Day said...

happy hug day 2016
happy hug day 2016 Date SMS Messages Quotes
Hug day Celebration Ideas
hug day sms for bf/gf

Silvia Jacinto said...

I really love your blog there's a lot to share. Keep it up.Visit my site too.

n8fan.net

www.n8fan.net

风骚达哥 said...

20160423 junda
air jordans
cheap oakley sunglasses
kate spade outlet
adidas stan smith
ray ban sunglasses
michael kors outlet
nike air max shoes
cheap omega watches
yeezy boost 350
michael kors outlet online
michael kors outlet online
nike free runs
air jordan uk
michael kors outlet online
pandora charms
ray ban outlet
calvin klein outlet
fitflops sale clearance
toms outlet
nike huarache white
sac longchamp
toms outlet
michael kors outlet clearance
bottega veneta outlet
armani watches
gucci handbags
nike blazer
oakley sunglasses
true religion jeans
cheap jordans
ray bans
hollister
bottega veneta handbags
jimmy choo outlet
oakley sunglasses
converse
prada outlet
reebok shoes
true religion
burberry outlet

Libin Huang said...

20160426libinhollister clothing store
oakley sunglasses
michael kors handbags
tiffany outlet
ray-ban sunglasses
gucci outlet online
ray-ban sunglasses
burberry outlet online
coach outlet canada
ray-ban sunglasses
herve leger outlet
ray ban sunglasses sale
air max 90
oakley sunglasses
adidas wings shoes
michael kors outlet
michael kors factory outlet
louis vuitton bags
michael kors online outlet
nba jerseys
ralph lauren pas cher
oakley sunglasses
toms shoes
nike air max 90
nike tn pas cher
air max 90
lululemon outlet
nike air force 1
true religion outlet
michael kors outlet
burberry outlet store
ray ban sunglasses
kobe shoes
true religion outlet
discount michael kors handbags

Yuanyuan Lin said...

7.14llllllyuan"timberland shoes"
"soccer jerseys wholesale"
"longchamp pliage"
"cheap oakley sunglasses"
"true religion jeans"
"louis vuitton pas cher"
"rolex orologi"
"christian louboutin shoes"
"michael kors clearance"
"cheap nba jerseys"
"oakley sunglasses wholesale"
"tory burch shoes"
"tory burch outlet"
"chicago blackhawks jerseys"
"longchamp outlet"
"omega watches"
"adidas trainers"
"cheap nike shoes"
"nike outlet store online"
"michael kors outlet clearance"
"michael kors uk"
"montblanc pens"
"michael kors canada"
"longchamp handbags"
"ray ban sunglasses"
"abercrombie and fitch"
"mcm outlet"
"puma shoes"
"ralph lauren uk"
"nike air max 90"
"rolex watches,rolex watches,swiss watches,watches for men,watches for women,omega watches,replica watches,rolex watches for sale,rolex replica,rolex watch,cartier watches,rolex submariner,fake rolex,rolex replica watches,replica rolex"
"mulberry outlet"
"air max 90"
"ferragamo outlet"
"christian louboutin outlet"
7.14

Fangyaya said...

michael kors handbags
coach factory outlet online
ghd flat iron
louis vuitton handbags
ralph lauren
polo shirts
ray ban sonnenbrille
nfl jerseys wholesale
kate spade outlet
ray ban sunglasses
coach outlet online
coach outlet online
louis vuitton outlet stores
christian louboutin sale
giuseppe zanotti sneakers
cheap ray ban sunglasses
michael kors outlet clearance
louboutin shoes
air jordan shoes
tods sale
replica rolex watches
coach outlet
coach outlet store online
louis vuitton outlet stores
coach outlet store online clearances
adidas yeezy
tory burch flats
polo ralph lauren
coach outlet store online clearances
air jordan 11
20168.8chenjinyan

Fangyaya said...

michael kors handbags
coach factory outlet online
ghd flat iron
louis vuitton handbags
ralph lauren
polo shirts
ray ban sonnenbrille
nfl jerseys wholesale
kate spade outlet
ray ban sunglasses
coach outlet online
coach outlet online
louis vuitton outlet stores
christian louboutin sale
giuseppe zanotti sneakers
cheap ray ban sunglasses
michael kors outlet clearance
louboutin shoes
air jordan shoes
tods sale
replica rolex watches
coach outlet
coach outlet store online
louis vuitton outlet stores
coach outlet store online clearances
adidas yeezy
tory burch flats
polo ralph lauren
coach outlet store online clearances
air jordan 11
20168.8chenjinyan

dada24 Xu said...

red bottoms shoes
louis vuitton bags
cheap oakley sunglasses
michael kors canada
true religion outlet store
doudoune moncler
levis outlet online
nike huarache
toms shoes outlet
ugg outlet
2016921caiyan

dada24 Xu said...

nmd adidas
oakley vault
cheap uggs
adidas nmd
moncler jackets
longchamp
michael kors outlet clearance
polo ralph lauren outlet online
michael kors watches
nike flyknit
2016921caiyan

chenlina said...

coach outlet
supra sneakers
the north face jackets
moncler uk
coach factory outlet
gucci uk
toms sale
louis vuitton outlet
replica watches
louis vuitton handbags
chenlina20160923

Paulo said...

They are hoping to collaborate with little organizations without taking value, partaking in benefits or settling on business choices. While they are prepared to give working funding to most substances, their emphasis is on business-to-business organizations. usapaydayloanstore.com/chicago

Paulo said...

Additional assets might be expected to manage a monetary issue instantly, so getting hands on the money immediately is the main alternative. With a payday or loan advance, candidates can get a $5,000 individual advance with terrible acknowledge as fast as in a couple of hours. Cash Advance San-diego

John said...

cheap rolex watches
hugo boss suits
ugg
michael kors uk
michael kors outlet clearance
ugg outlet online
cheap jordan shoes
canada goose jackets uk
yeezy shoes
cheap jerseys wholesale
uggs sale
adidas yeezy boost 350
authentic louis vuitton handbags
ugg canada sale
ugg boots
louis vuitton outlet online
michael kors outlet store
michael kors
ed hardy clothing
ray ban glasses
michael kors
michael kors uk
red bottom shoes
fitflops
chaussure louboutin
coach factory outlet online
true religion jeans outlet
levi's jeans
ed hardy store
20161102yuanyuan

Outlet Wade said...

just not an association. But today I have been hit by the Michael Kors beauty truck. There Michael Kors Outlet is something about this bag that just looks so supple, rich, and creamy that I can not ignore it. The Michael Coach Outlet Online Kors Ostrich Drawstring Satchel is bold and beautifully with its peanut ostrich body and perfectly accenting brown leather trim. The two Longchamp Handbags shades of brown remind me of some creamy dessert and since I have such a sweet tooth, it makes me smile. michael kors outlet The top handles show off detailed stitching along with the rest of the bags contrast stitching. I am not always a michael kors fan of drawstring tops, but this top with beaded ties brings the bags goodness together in a way I can’t describe. michael kors outlet online The hardware and studs are golden which compliment the other colors and materials. On the front, there are two flap pockets Coach Bags with extended tabs. I can’t figure it all out, but there is something so alluring about this bag for me that Michael Kors Handbags I just keep looking at it and wishing it was mine. If you love me you will put yourself on the Longchamp Bag pre-order list and buy this beauty via Bergdorf goodman for $3,000. And, I will accept charity today and happily take this Michael Kors bag if you buy it for me :-)

Paulo said...

Because of a quick development in economy, the land costs are rising step by step. The purchasers can make an immense benefit by purchasing bank claimed properties and after that offering at great costs later on. check cashing

huali10 Cai said...

rolex watches for sale
louis vuitton
cheap jordans for sale
air max 90
longchamp outlet
nike outlet store online
tory burch outlet online
futbol baratas
cheap oakley sunglasses
michael kors outlet clearance
qqqqqing20170411

xjd7410@gmail.com said...

polo ralph lauren outlet
michael kors handbags
mlb jerseys
cheap nfl jerseys
asics,asics israel,asics shoes,asics running shoes,asics israel,asics gel,asics running,asics gel nimbus,asics gel kayano
foamposite shoes
louis vuitton outlet
chrome hearts
oakley sunglasses sale
fitflops uk
chanyuan2017.05.24

raybanoutlet001 said...

toms shoes
nike huarache
valentino outlet
ed hardy
michael kors handbags
fitflops
mont blanc outlet
atlanta falcons jerseys
nike air max 90
nike huarache