Saturday, January 21, 2012

Loop through all webs faster way in SharePoint 2010

We are learning so many concepts each day and implementing/writing lot of code. But, we might not spending time to write the code more efficient way or more cleaner way. So, this post is again related to how to write code efficient in SharePoint 2010. :)

So far, till SharePoint 2007 to loop through all the webs in site collection we use the code:
using(SPSite site = new SPSite("http://sitecollectionurl")
foreach(SPWeb web in site.AllWebs)
//Some code here
The above code is not at all wrong.

Case 1:
If you need the web object only for reading the generic information of the site like title, url, id etc… then it is a very expensive operation. For this, in SharePoint 2010 there is a workaround and that will load results 10 times faster than above code. Below is the efficient code:
using(SPSite site = new SPSite("http://sitecollectionurl")
foreach(SPWebInfo webInfo in site.AllWebs.WebsInfo)
//Code here to read web information 
This way you only reading the web information object instead of complete Web object. You can take a look more about WebInfo class here in MSDN.

Case 2:
If you want to read the properties you needed then there is a more better way than simply loop through AllWebs property in for each. The complete explaination is here. This is a very good post and very very faster way to read the properties in all webs.

You really see the difference, a big difference. Do you like this post?

Wednesday, January 11, 2012

Download Visual Studio 11 Developer Preview - now with SharePoint developer tools

Visual Studio 11 Developer Preview is now available with the SharePoint developer tools and downloadable to public. Earlier version only has the Windows 8 stuff as a new thing along with some user experience improvements. But, in the new version it has the SharePoint developer tools added. So, as I am a SharePoint guy I would like to see what are all the features available in the new version.

Visual Studio 11 is very fast when compared to Visual Studio 2010 and it definitely improves the productivity. This is one of the major point which I like about it. When come back to what are the new features added in SharePoint developer tools, below are the few of them.
  • Create Lists and Content Types by Using New Designers
  • Create Site Columns
  • Create Silverlight Web Parts
  • Publish SharePoint Solutions to Remote SharePoint Servers
  • Test SharePoint Performance by Using Profiling Tools
  • Create Sandboxed Visual Web Parts
  • Improved Support for Sandboxed Solutions.
  • Support for JavaScript Debugging and IntelliSense for JavaScript
  • Streamlined SharePoint Project Templates
  • Related Topics
The MSDN link has all these features explained. Stay tuned for the more updates from this blog as I like to publish more articles on what next...