This is related how instance of SPListItem is being created. Actually in both cases new item is added to the collection of items in list, in first case new item is added explicitly, in the second one implicitly.
The point is, that for initializing collection of items in list is used the same method GetItems but with different queries.
It sure looks so from your story, but isn't there a quite easy workaround for this?
<FieldRef Name="ID" />
Generally speaking you will want to use SPQuery to only query items you're interested in.
Unless you're doing
SPList oList = web.GetList("XYZ");
for(int i=0; i < oList.Items.Count; i++)
string strLstItemName = oList.Items[i].Name; // << BAD, as you use Items here, so you fetch them from DB each loop
there shouldn't be any relevant ...
Make sure that the column you include in the where clause is defined as an indexed column in SharePoint. You can check by going to the list you're querying and into List -> Settings -> Indexed Columns. It's not applicable in your CAML query, but if you have more than one 'where', ensuring the first where hits an indexed column can increase efficiency.
Working solution from StackEchange link
var context = SP.ClientContext.get_current();
var myListItem = context.get_web().get_lists().getByTitle("ListName").getItemById(1);
Can't comment due to low rep so posting as an answer, purists forgive.
Breaking a 500 element In into several nested Or tags does not work, to my despair. The limit is 500 elements hard apparently.
I have tried breaking using a limit of 500 elements, 400, 300, 200, 100, and the SPServices query failed, returning: 500 Internal Server Error with the ...
You could sort list items using array.sort function:
var ctx = SP.ClientContext.get_current();
var list = ctx.get_web().get_lists().getByTitle(listTitle);
var items = list.getItems(SP.CamlQuery.createAllItemsQuery());
You have to iterate through DataTable and fill into SPListitemCollection object.
Also check following link for the code details:
You can get items collection very simply. Try this code:
public static SPListItemCollection GetItemsRecursive(SPFolder folder)
SPList list = folder.ParentWeb.Lists[folder.ParentListId];
SPQuery query = new SPQuery();
query.Folder = folder; //set folder for seaching;
query.ViewAttributes = "Scope=\"Recursive\""; //set ...
This answer has two parts:
First, for maximum performance and scalability, to retrieve the lists you should be using web.Lists[Guid]. Iterating through web.Lists and picking your selected lists, or using web.Lists[Name] (which also iterates through the set internally) will causes the API to retrieve metadata for all SPList objects under that SPWeb, which ...
There is no memory leak in your code for SPWeb. The SPWeb object you get from SPContext.Current.Site.OpenWeb(webUrl) should be disposed (like you already did).
There is are other performance improvements I can suggest in your code:
1) Use list = web.GetList(lstUrl) instead of list = web.Lists[listName] ;
2) Use list.GetItems([SPQuery]) instead of list....
You're disposing an instance of SPWeb got through using SPContext. This probably will result in unpredictable behaviour as something else is expecting to dispose of the Site object you've got it from.
Rather, use new SPSite(SPContext.Current.Site.Url) and wrap that in a using tag like you've done there.
EDIT: Yeah, you're using OpenWeb() which does indeed ...
I don't like using  to get the SPListItem...interested in reccomendations
Well, SPList.Items syntax fetch ALL THE DATA from SharePoint and after - give you item by index. That's a common behavior.
You might use also SPList.GetItemById or similar methods or even make a caml query against the target list w/ SPList.GetItems method. It's up ...
There is no buildin way to get all the lists in a site collection.
Your method of looping through AllWebs and getting the Lists collection for each is the only way, but it's not efficient, so you probably want to build some cache or maintain your own list and updated it using a EventReceiver each time a list is create/delete or when a site is deleted.
All answers are not safe, when the field is null. This can happen, when a field gets later added and already items are in this list.
This is a safe cast:
bool? showTitle = properties.ListItem["ShowTitle"] as bool?;
if (showTitle.HasValue && showTitle.Value)
The value of an Url field is stored internally as an url/description couple. What you are fetching is the string representation of that value.
To obtain the actual values, the preferred way is to use the SPFieldUrlValue class. You need to create a new istance of the class from the field string value - you will then be able to read the desired url and ...
A little more background, AddItem() is the preferred method because as the list gets larger, it has to download all the items in the list when you call list.items.add() in order to add the one item.
This is why MS created the AddItem() call so that you could add an item without doing a query of all items in the list.
Avoid calling .Items off of a SPList ...
Alternatively, you could use SPFieldLookupValue (for a single lookup) and SPFieldLookupValueCollection (for a multi-lookup) to parse the field values using SharePoint's built-in methods for processing them.
Here is a revised version of your function for single lookups:
protected string RemoveCharacters(string fieldValue)
SPFieldLookupValue value = ...
For this you need to increase the Threshold value first and then get the list item count.
You can increase it either programmatically or powershell or Central admin.
Ex.. through powershell
$WebApplication = Get-SPWeb http://
$List = $WebApplication.Lists["My List"]
$List.EnableThrottling = $false
The above mentioned techniques would have only work if DataTable would have been derived from SPListItemCollection.
Since its not the case, so you will have to iterate over the rows in DataTable and will have to create list items for each row and associate it with appropriate properties.
There are two options in sharepoint to delete the listitem:
listitem.Recycle() deletes the list item and puts it in the recycle bin
listitem.Delete() deletes the item permanently
If you delete a document in SharePoint using the User Interface, it’s being moved to the Recycle Bin, so that it can be restored if necessary. Calling the SPListItem.Delete() ...
In the context of general c# comparistions between for and foreach - There is a pretty comphrensive discussion here
for loops on List are a bit more than 2 times cheaper than foreach loops on List.
Looping on array is around 2 times cheaper than looping on List.
As a consequence, looping on array using for is 5 times cheaper than looping on List ...
Author is the person who created the item. It is assigned once the item is created and never changed.
Editor is changed every time item is modified.
Better use SPFieldUserValue to retrieve SPUser.
foreach (SPListItem item in myItemCol)
SPFieldUserValue usrAuthor = new SPFieldUserValue(SPContext.Current.Web, item["Author"].ToString());
author = ...
This post answered my question.
List<SPListItem> allItems = new List<SPListItem>();
//Do something to the "allItems"