<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Kommentare zu: The wrong way to iterate through SharePoint SPList Items</title>
	<atom:link href="http://blog.dynatrace.com/2009/01/11/the-wrong-way-to-iterate-through-sharepoint-splist-items/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.dynatrace.com/2009/01/11/the-wrong-way-to-iterate-through-sharepoint-splist-items/</link>
	<description></description>
	<lastBuildDate>Thu, 09 Feb 2012 06:14:18 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
	<item>
		<title>Von: Shaheen Aggarwal</title>
		<link>http://blog.dynatrace.com/2009/01/11/the-wrong-way-to-iterate-through-sharepoint-splist-items/comment-page-1/#comment-20693</link>
		<dc:creator>Shaheen Aggarwal</dc:creator>
		<pubDate>Mon, 27 Sep 2010 06:25:01 +0000</pubDate>
		<guid isPermaLink="false">http://blog.dynatrace.com/?p=263#comment-20693</guid>
		<description>Thanks, Nice article!</description>
		<content:encoded><![CDATA[<p>Thanks, Nice article!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Von: Todd C. Bleeker</title>
		<link>http://blog.dynatrace.com/2009/01/11/the-wrong-way-to-iterate-through-sharepoint-splist-items/comment-page-1/#comment-16998</link>
		<dc:creator>Todd C. Bleeker</dc:creator>
		<pubDate>Tue, 06 Jul 2010 20:17:31 +0000</pubDate>
		<guid isPermaLink="false">http://blog.dynatrace.com/?p=263#comment-16998</guid>
		<description>Andreas,

Awesome. I didn&#039;t know about the other articles in your series. Keep up the good work then.  : )

</description>
		<content:encoded><![CDATA[<p>Andreas,</p>
<p>Awesome. I didn&#8217;t know about the other articles in your series. Keep up the good work then.  : )</p>
]]></content:encoded>
	</item>
	<item>
		<title>Von: Andreas Grabner</title>
		<link>http://blog.dynatrace.com/2009/01/11/the-wrong-way-to-iterate-through-sharepoint-splist-items/comment-page-1/#comment-16957</link>
		<dc:creator>Andreas Grabner</dc:creator>
		<pubDate>Sun, 04 Jul 2010 15:27:23 +0000</pubDate>
		<guid isPermaLink="false">http://blog.dynatrace.com/?p=263#comment-16957</guid>
		<description>Hi Todd
Thanks for your comment. I wrote a series of blog entries about SharePoint Performance on Lists and Views. If you click on the SharePoint tag you will find all my other blogs. I also cover CAML and how it allows you to be very specific with not only querying fewer elements but also returning fewer columns (Just query what you really need).
I also cover your proposed solution with iterating through the list.
The reason why I posted all these blog posts is because I&#039;ve seen several people (clients of ours) using the SharePoint Object Model in a way that is very inefficient. I hoped to educate people with these blogs on how to do better.

Thanks again - postings and comments like yours will help the SharePoint Devs out there to get a better understanding of the internals of SharePoint and how to best use it</description>
		<content:encoded><![CDATA[<p>Hi Todd<br />
Thanks for your comment. I wrote a series of blog entries about SharePoint Performance on Lists and Views. If you click on the SharePoint tag you will find all my other blogs. I also cover CAML and how it allows you to be very specific with not only querying fewer elements but also returning fewer columns (Just query what you really need).<br />
I also cover your proposed solution with iterating through the list.<br />
The reason why I posted all these blog posts is because I&#8217;ve seen several people (clients of ours) using the SharePoint Object Model in a way that is very inefficient. I hoped to educate people with these blogs on how to do better.</p>
<p>Thanks again &#8211; postings and comments like yours will help the SharePoint Devs out there to get a better understanding of the internals of SharePoint and how to best use it</p>
]]></content:encoded>
	</item>
	<item>
		<title>Von: Todd C. Bleeker</title>
		<link>http://blog.dynatrace.com/2009/01/11/the-wrong-way-to-iterate-through-sharepoint-splist-items/comment-page-1/#comment-16910</link>
		<dc:creator>Todd C. Bleeker</dc:creator>
		<pubDate>Fri, 02 Jul 2010 22:14:39 +0000</pubDate>
		<guid isPermaLink="false">http://blog.dynatrace.com/?p=263#comment-16910</guid>
		<description>Since my response didn&#039;t show up well in the comments section here. I&#039;ve reposted my response on my own blog:
http://sharepoint.mindsharpblogs.com/Todd/archive/2010/07/02/Performant-Iteration-of-an-SPListItemCollection.aspx

</description>
		<content:encoded><![CDATA[<p>Since my response didn&#8217;t show up well in the comments section here. I&#8217;ve reposted my response on my own blog:<br />
<a href="http://sharepoint.mindsharpblogs.com/Todd/archive/2010/07/02/Performant-Iteration-of-an-SPListItemCollection.aspx" rel="nofollow"></a><a href='http://sharepoint.mindsharpblogs.com/Todd/archive/2010/07/02/Performant-Iteration-of-an-SPListItemCollection.aspx'>http://sharepoint.mindsharpblogs.com/Todd/archive/2010/07/02/Performant-Iteration-of-an-SPListItemCollection.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>Von: Todd C. Bleeker</title>
		<link>http://blog.dynatrace.com/2009/01/11/the-wrong-way-to-iterate-through-sharepoint-splist-items/comment-page-1/#comment-16909</link>
		<dc:creator>Todd C. Bleeker</dc:creator>
		<pubDate>Fri, 02 Jul 2010 22:07:06 +0000</pubDate>
		<guid isPermaLink="false">http://blog.dynatrace.com/?p=263#comment-16909</guid>
		<description>Andreas,

First, you should very rarely use a for index to iterate any collection in SharePoint. The SharePoint API will &quot;do the right thing&quot; (including using cache when appropriate, using good SQL query techniques, and the pre-creation of the next object in anticipation of the likely continued loop) in most circumstances when you use foreach for iteration instead. So, the code above would better be written as follows:

SPListItemCollection items =
  SPContext.Current.List.Items;
foreach(SPListItem item in items)
{
  htmlWriter.Write(item[&quot;Title&quot;]);
}

Not only is this more performant but it is easier to read so general supportability will improve too. I&#039;ll leave the suspicious SPContext.Current.List and htmlWriter for someone else to take issue with.


Second, retrieving the entire SPListItemCollection into memory can have it&#039;s own set of problems. Consider the situation where there are thousands of list items with dozens of columns. That will produce quite a memory footprint just to write out the title of each SPListItem.

I would highly recommend that you consider a CAML query that restricts the fields and may even filter the list items retrieved (or use LINQ to SharePoint 2010 which will generate a CAML query) and the GetItems method.

The following example code will run in a Console App and it reads the SPListItem with a Title of &quot;One&quot; from the Tasks list in a Site Collection found at http://localhost. Even though this includes a sort, it is far more performant than the iteration originally demonstrated in this blog post. I parsed it down to just the Title of a single SPListItem to give the most comprehensive yet still simple example:

using (SPSite siteCollection =
  new SPSite(&quot;http://localhost&quot;))
{
  SPWeb web = siteCollection.RootWeb;
  SPList list = web.Lists[&quot;Tasks&quot;];

  if (null != list)
  {
    StringBuilder sb = new StringBuilder();

    sb.Append(&quot;&quot;)
      .Append(&quot;  &quot;)
      .Append(&quot;    &quot;)
      .Append(&quot;    One&quot;)
      .Append(&quot;  &quot;)
      .Append(&quot;&quot;)
      .Append(&quot;&quot;)
      .Append(&quot;  &quot;)
      .Append(&quot;&quot;);

    SPQuery qry = new SPQuery();
    qry.ViewFields = &quot;&quot;;
    qry.Query = sb.ToString();
    qry.ViewFieldsOnly = True;

    SPListItemCollection items = list.GetItems(qry);
    foreach (SPListItem item in items)
    {
      Console.WriteLine(item[&quot;Title&quot;]);
    }
  }

  Console.WriteLine(&quot;---Done&quot;);
  Console.ReadLine();
}
 
For even more robust sample code, see the ViewFields entry in the SDK:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spquery.viewfields.aspx

HTH,

</description>
		<content:encoded><![CDATA[<p>Andreas,</p>
<p>First, you should very rarely use a for index to iterate any collection in SharePoint. The SharePoint API will &#8220;do the right thing&#8221; (including using cache when appropriate, using good SQL query techniques, and the pre-creation of the next object in anticipation of the likely continued loop) in most circumstances when you use foreach for iteration instead. So, the code above would better be written as follows:</p>
<p>SPListItemCollection items =<br />
  SPContext.Current.List.Items;<br />
foreach(SPListItem item in items)<br />
{<br />
  htmlWriter.Write(item["Title"]);<br />
}</p>
<p>Not only is this more performant but it is easier to read so general supportability will improve too. I&#8217;ll leave the suspicious SPContext.Current.List and htmlWriter for someone else to take issue with.</p>
<p>Second, retrieving the entire SPListItemCollection into memory can have it&#8217;s own set of problems. Consider the situation where there are thousands of list items with dozens of columns. That will produce quite a memory footprint just to write out the title of each SPListItem.</p>
<p>I would highly recommend that you consider a CAML query that restricts the fields and may even filter the list items retrieved (or use LINQ to SharePoint 2010 which will generate a CAML query) and the GetItems method.</p>
<p>The following example code will run in a Console App and it reads the SPListItem with a Title of &#8220;One&#8221; from the Tasks list in a Site Collection found at <a href="http://localhost" rel="nofollow"></a><a href='http://localhost'>http://localhost</a>. Even though this includes a sort, it is far more performant than the iteration originally demonstrated in this blog post. I parsed it down to just the Title of a single SPListItem to give the most comprehensive yet still simple example:</p>
<p>using (SPSite siteCollection =<br />
  new SPSite(&#8220;http://localhost&#8221;))<br />
{<br />
  SPWeb web = siteCollection.RootWeb;<br />
  SPList list = web.Lists["Tasks"];</p>
<p>  if (null != list)<br />
  {<br />
    StringBuilder sb = new StringBuilder();</p>
<p>    sb.Append(&#8220;&#8221;)<br />
      .Append(&#8221;  &#8220;)<br />
      .Append(&#8221;    &#8220;)<br />
      .Append(&#8221;    One&#8221;)<br />
      .Append(&#8221;  &#8220;)<br />
      .Append(&#8220;&#8221;)<br />
      .Append(&#8220;&#8221;)<br />
      .Append(&#8221;  &#8220;)<br />
      .Append(&#8220;&#8221;);</p>
<p>    SPQuery qry = new SPQuery();<br />
    qry.ViewFields = &#8220;&#8221;;<br />
    qry.Query = sb.ToString();<br />
    qry.ViewFieldsOnly = True;</p>
<p>    SPListItemCollection items = list.GetItems(qry);<br />
    foreach (SPListItem item in items)<br />
    {<br />
      Console.WriteLine(item["Title"]);<br />
    }<br />
  }</p>
<p>  Console.WriteLine(&#8220;&#8212;Done&#8221;);<br />
  Console.ReadLine();<br />
}</p>
<p>For even more robust sample code, see the ViewFields entry in the SDK:<br />
<a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spquery.viewfields.aspx" rel="nofollow"></a><a href='http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spquery.viewfields.aspx'>http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spquery.viewfields.aspx</a></p>
<p>HTH,</p>
]]></content:encoded>
	</item>
	<item>
		<title>Von: How to avoid the Top 5 SharePoint Performance Mistakes Performance, Scalability and Architecture &#8211; Java and .NET Application Performance Management (dynaTrace Blog)</title>
		<link>http://blog.dynatrace.com/2009/01/11/the-wrong-way-to-iterate-through-sharepoint-splist-items/comment-page-1/#comment-13716</link>
		<dc:creator>How to avoid the Top 5 SharePoint Performance Mistakes Performance, Scalability and Architecture &#8211; Java and .NET Application Performance Management (dynaTrace Blog)</dc:creator>
		<pubDate>Thu, 18 Mar 2010 15:21:43 +0000</pubDate>
		<guid isPermaLink="false">http://blog.dynatrace.com/?p=263#comment-13716</guid>
		<description>[...] readings: The wrong way to iterate through SharePoint SPList Items and Performance Considerations when using the SharePoint Object [...]</description>
		<content:encoded><![CDATA[<p>[...] readings: The wrong way to iterate through SharePoint SPList Items and Performance Considerations when using the SharePoint Object [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>Von: Andreas Grabner</title>
		<link>http://blog.dynatrace.com/2009/01/11/the-wrong-way-to-iterate-through-sharepoint-splist-items/comment-page-1/#comment-10853</link>
		<dc:creator>Andreas Grabner</dc:creator>
		<pubDate>Sun, 10 Jan 2010 10:29:05 +0000</pubDate>
		<guid isPermaLink="false">http://blog.dynatrace.com/?p=263#comment-10853</guid>
		<description>@Michhes: using SPList.ItemCount is a good way of getting the number of elements. It doesn&#039;t require a roundtrip to the database as the itemcount is kept in memory. Check out my other blogs on the SharePoint topic - you will find some more useful information about the SharePoint API</description>
		<content:encoded><![CDATA[<p>@Michhes: using SPList.ItemCount is a good way of getting the number of elements. It doesn&#8217;t require a roundtrip to the database as the itemcount is kept in memory. Check out my other blogs on the SharePoint topic &#8211; you will find some more useful information about the SharePoint API</p>
]]></content:encoded>
	</item>
	<item>
		<title>Von: Michhes</title>
		<link>http://blog.dynatrace.com/2009/01/11/the-wrong-way-to-iterate-through-sharepoint-splist-items/comment-page-1/#comment-10824</link>
		<dc:creator>Michhes</dc:creator>
		<pubDate>Sat, 09 Jan 2010 15:23:43 +0000</pubDate>
		<guid isPermaLink="false">http://blog.dynatrace.com/?p=263#comment-10824</guid>
		<description>I use SPList.ItemCount instead and/or an alternative access method (eg. GetItems() with a CAML query). 

See http://msdn.microsoft.com/en-us/library/bb687949.aspx</description>
		<content:encoded><![CDATA[<p>I use SPList.ItemCount instead and/or an alternative access method (eg. GetItems() with a CAML query). </p>
<p>See <a href="http://msdn.microsoft.com/en-us/library/bb687949.aspx" rel="nofollow"></a><a href='http://msdn.microsoft.com/en-us/library/bb687949.aspx'>http://msdn.microsoft.com/en-us/library/bb687949.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>Von: SharePoint: Only request data that you really need Performance, Scalability and Architecture &#8211; Java and .NET Application Performance Management (dynaTrace Blog)</title>
		<link>http://blog.dynatrace.com/2009/01/11/the-wrong-way-to-iterate-through-sharepoint-splist-items/comment-page-1/#comment-6090</link>
		<dc:creator>SharePoint: Only request data that you really need Performance, Scalability and Architecture &#8211; Java and .NET Application Performance Management (dynaTrace Blog)</dc:creator>
		<pubDate>Sat, 12 Sep 2009 19:28:16 +0000</pubDate>
		<guid isPermaLink="false">http://blog.dynatrace.com/?p=263#comment-6090</guid>
		<description>[...] back at the previous two posts (Scenario 1, Scenario 2) you can see that the executed SQL Statement always selected ALL items from requested SharePoint [...]</description>
		<content:encoded><![CDATA[<p>[...] back at the previous two posts (Scenario 1, Scenario 2) you can see that the executed SQL Statement always selected ALL items from requested SharePoint [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>Von: Iteration versus Catching Expected Exceptions &#171; SharePoint 2007 Hut</title>
		<link>http://blog.dynatrace.com/2009/01/11/the-wrong-way-to-iterate-through-sharepoint-splist-items/comment-page-1/#comment-2391</link>
		<dc:creator>Iteration versus Catching Expected Exceptions &#171; SharePoint 2007 Hut</dc:creator>
		<pubDate>Wed, 22 Apr 2009 14:49:07 +0000</pubDate>
		<guid isPermaLink="false">http://blog.dynatrace.com/?p=263#comment-2391</guid>
		<description>[...] how to iterate, check this blog. Possibly related posts: (automatically generated)Java generics gotchaMore ArcGIS Geoprocessing [...]</description>
		<content:encoded><![CDATA[<p>[...] how to iterate, check this blog. Possibly related posts: (automatically generated)Java generics gotchaMore ArcGIS Geoprocessing [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

