Skip to content
March 17, 2011 / kiranpatils

Do you know how GetItem method works?


If you have used Performance counters with your site core and observed something strange behavior with GetItem method and ItemsAccessed counter then this blog is a good read for you OR you want to know How GetItem method works please keep reading this article.


GeItem works like this:

“The GetItem() method just take the  root item and tries to find the requested item among its children. If requested item isn’t found, it takes child item and search in its children and so on. This is why GetItem() method access so many items.”

What we were trying is as below:

1. We configured ItemsAccessed Sitecore performance counter.

2. Now, in our custom control we used database.GetItem(“DUMMYITEMWITHFULLPATH”);

3. And ran our sitecore’ instance.

4. And it gave us totally weird results. ItemsAccess counter value was reaching approx. 17000 even though item doesn’t exist.

Now, what best we can do to get an item?

You can use Sitecore.Context.Database.SelectSingleItem() method which is far better than GetItem. But in life good comes with something bad and that holds true for this method as well:

SelectSingleItem method use the direct request to the database, so it works faster. However, it have some disadvantages:

1. Security check won’t be performed
2. Virtual items can’t be returned

If these disadvantages isn’t matter for you, feel free to use SelectSingleItem method instead of GetItem.

Happy Coding! 🙂

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

%d bloggers like this: