Monday, April 8, 2013

How to Access the List Items

wrong way :

This will increase network traffic to access data from Database each time

SPList masterPages = root.Lists.TryGetList("Master Page Gallery");
if (masterPages != null)
{
foreach (SPListItem fileItem in masterPages.Items)
{
SPFile file = fileItem.File;
Console.WriteLine(file.Name);
}
}


Correct way :

Below Code will store the List Items in the SPListitemCollection.

SPList masterPages = root.Lists.TryGetList("Master Page Gallery");
if (masterPages != null)
{
SPListItemCollection items = masterPages.Items;
foreach (SPListItem fileItem in items)
{
SPFile file = fileItem.File;
Console.WriteLine(file.Name);
}
}

No comments:

Post a Comment

HTML

Script:

JS