As others have said, you should not iterate over the Items collection directly (especially in large collections). There is alternaltive here:
// if you need the whole collection. Otherwise use SPQuery in the list
DataTable dt = list.Items.GetDataTable(); foreach (DataRow row in dt.Rows) { ...
Then you can do many things. If you need to check to get only some of the elements, for example:
if (row["ContentType"].ToString().Equals("Your contenttype id")) { SPListItem item = list.GetItemById((int)row["ID"]);
or use SpQuery to get the column in the query, for example:
SPQuery oQuery = new SPQuery(); oQuery.ViewFields = "<FieldRef Name='UrlColumn'/>"; list.Items.GetItems(oQuery).GetDataTable(); ...foreach code... row["UrlColumn"]
Johan leino
source share