Is there any difference in below statement or are they same?
SPListItem[field_Name]
vs SPListItem.Properties[field_Name]
Where field_Name is column name in a sharepoint list.
And which one is better to use in reference to optimaztion
Both are different. SPListItem.Properties
is a hashtable
which can be used to store key value pairs. It is also known as List item property bag in SharePoint.
In ASP.Net web application, whenever we need configuration data (key-value pair), we store that data in web.config file in AppSetting and retrieve configurations from config according to our need. Like AppSetting, SharePoint provides property bag at each level for your SharePoint Application Development SharePoint provides Property bags to store and retrieve configuration at various levels like:
- Farm Level - SPFarm
- Web Application Level - SPWebApplication
- Web Level - SPWeb Level
- Item Level - SPListItem
Whereas SPListItem[field_Name]
is used to get/set value of a field in a SharePoint List item. Example to store value in list item property bag:
using (SPSite site = new SPSite("http://aissp2013/sites/Team"))
{
SPWeb web = site.RootWeb;
SPList list = web.Lists["Employees"];
SPListItem item = list.GetItemById(1);
item.Properties.Add("Employee Name", "Nadeem Yousuf");
item.Update();
list.Update();
}
See more at http://www.tekritisoftware.com/using-sharepoint-property-bag-in-your-sharepoint-application