This post is migrated from previous hosting provider. There are still some issues with old posts. Please make a comment on this post with any issues.

Four interesting changes to the SharePoint Foundation 2010 API

Tags: SharePoint 2010

Working with SharePoint 2010 is really a joy, you stumble upon great things all the time. The API has not had any revolutionary changes to be backwards compatible; but small changes here and there, both publically visible and internally, really makes the API better than before.

SPListItem.SPContentTypeId

To get the Content Type Id of an SPListItem you had to first get the SPContentType from the SPListItem.ContentType and then get the Id of the content type. This method was one marked as internal in version 12, but is now marked 14. It’s those little things. There are actually a lot of previously internal properties and methods that now are public, for example the CanBeDisplayedInEditForm property on the SPField class.

SPListCollection.TryGetList(string listTitle)

Last year I wrote a post about this one and now it’s there. No need to encapsulate your code with try-catch blocks when trying to get a list using it’s name. TryGetList will return null if the list does not exist. Thank you guys, up there in Redmond!

SPWebPartManager disposes the SPWeb object

One change that is really great. When using the SPWebPartManager or the SPLimitedWebPartManager you previously had to manually dispose the SPWeb object before disposing the Web Part manager, now that’s done when disposing the SPWebPartManager or the SPLimitedWebPartManager. This will save a lot of people a lot of memory leaks.

SPField.ListFieldUsedIn(…)

This is an interesting one, using this method you can find out which sites and lists a specific field is used. The method returns a collection of SPFieldTemplateUsage objects, which contains Guids of the list and site Id’s. One thing that also is interesting with this one is the usage of the templated ICollection instead of an array or custom collection.

There are of course a lot more, but these four I did find during my excavations this weekend. Have you found any favorite change except the obvious ones?

8 Comments

  • Liz said

    If you think the SharePoint 2010 API is a joy you need to look at the MindTouch API http://developer.mindtouch.com/index.php?title=Deki/API_Reference . I've been building on this for the last couple years and the ease to extend and develop is a joy. This is a great alt to SharePoint and is also a great way to extend SharePoint. Check out: www.mindtouch.com

  • turbo said

    <b><a href="http://www.bestturbofireworkout.com/" target="TurboFire">TurboFire</a></b> is a High Intensity Interval Training or "H.I.I.T" dedicated to get people in the best shape of there life in just 12 short weeks.The best way to lose weight is to be active and follow a healthy regime. No crash diet will help you lose weight or maintain it that way. <b><a href="http://www.bestturbofireworkout.com/" target="Turbo Fire workout">Turbo Fire workout</a></b> will help you realize it. <b><a href="http://www.bestturbofireworkout.com/" target="Turbo Fire">Turbo Fire</a></b> sale!

  • Ryan Reynolds said

    Last year I wrote a post about this one and now it’s there. No need to encapsulate your code with try-catch blocks when trying to get a list using it’s name. TryGetList will return null if the list does not exist. Thank you guys, up there in Redmond!

  • Russian connections online said

    Searched for the information on this theme, and only here I found it. This is an interesting one, using this method you can find out which sites and lists a specific field is used. The method returns a collection of SPFieldTemplateUsage objects, which contains Guids of the list and site Id’s. One thing that also is interesting with this one is the usage of the templated ICollection instead of an array or custom collection.

Comments have been disabled for this content.

About Wictor...

Wictor Wilén is the Nordic Digital Workplace Lead working at Avanade. Wictor has achieved the Microsoft Certified Architect (MCA) - SharePoint 2010, Microsoft Certified Solutions Master (MCSM) - SharePoint  and Microsoft Certified Master (MCM) - SharePoint 2010 certifications. He has also been awarded Microsoft Most Valuable Professional (MVP) for seven consecutive years.

And a word from our sponsors...