SP Best Prectices

1. First see the Difference between two? And then USE.

web.Lists[“Demo”] and web.GetList(“http://localhost:90/Demo/AllItems.aspx”) In my case http://usctap3452/sites/sa/SubCategory/AllItems.aspx 🙂

web.Lists[ListName] method :In this case, it loads the metadata* of the all lists in that specific SPWeb object. Then it does SPList.Title comparison with metadata of all the lists returned and then it returns the matching list from the SPWeb.Lists collection.

web.GetList(URL) method : In this case, first retrieves the list GUID from the url (database hit), then it loads the metadata for that specific list.

Conclusion : if u have a Large collection of lists in urs Site avoid using web.Lists[] method

2. Which one to use objList.Items.Count or objList.ItemsCount.

objList.Items.Count:First it will load all the SPListItems in the memory and then it will find out the total count.Bad Practice

objList.ItemsCount:ItemCount is a part of metadata of the SPList object and this will get generated whenver we create a SPList instance. So there is no any overburden to the list to find out its total number of list items.

Conclusion :Always use objList.ItemsCount

3. Never create Do not instantiate SPWeb, SPSite, SPList, or SPListItem objects within an

public override void ItemAdded(SPItemEventProperties properties)
{
using (SPSite objSite = new SPSite(properties.WebUrl))
{
using (SPWeb objWeb = objSite.OpenWeb())
{
SPList objList = objWeb.Lists[properties.ListId];
SPListItem objListItem = oList.GetItemByUniqueId(properties.ListItemId);
}
}
}

this is bad practice

public override void ItemAdded(SPItemEventProperties properties)
{
SPListItem oItem = properties.ListItem;
}

Conclusion :Always use second One

About Krishana Kumar

Krishana Kumar is SharePoint Architect/Trainer having Architecture experience with high volumes at Enterprise level and global scale - creation of highly scalable solutions with global user base and geographically distributed architectural components. Good knowledge of SharePoint best practices and governance models. I hold Two Master degree in Computer Science with over 11 years of experience working on Microsoft Technologies specially SharePoint, Project, .NET and other Information Worker Technologies. Having good exposer in Client side scripting Angular.js, backbone and Node. I am currently responsible for SharePoint Infrastructure set up and leading teams in various medium and large scale projects, architecting, designing & installing SharePoint farms, developing custom components,, and providing advanced SharePoint administration and development training to teams and customers. I regularly speaks in various SharePoint User Groups and other Events. I have MCSA Windows Azure, MCSA Office 365, MCSE & MCSD SharePoint 2013, Microsoft Certified Developer (MCD) and holds MCPD, MCTIP and MCTS for SharePoint 2010, MCTS MOSS 2007 & WSS 3.0, MCPD, MCITP (EPM 2010 & 2007) and MCSD .NET.
This entry was posted in General Interest. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *