SharePoint: Well, that’s how I would have done it

So, I’ve been trying to iterate over the items in a discussion list.

I was doing the following:

SPList discussionList = web.Lists[“Discussions”];
string sID= discussionList.ItemCount.ToString();

foreach (SPListItem spLI in discussionList.Items)
sID= spLI.UniqueId.ToString();

Even though the ItemCount property was returning 2, I wasn’t seeing any items. Then, I noticed that if I used discussionList.Items.Count, I was getting 0.

Turns out SharePoint only returns REPLIES as Items. The initial part of a discussion is treated as a FOLDER. (Makes total sense….)

This will give you all the list items which have a reply message to it:

SPLists Lists = Web.Lists();
foreach (spListItem item in Lists.Items)

However, if you want the list items that don’t have a reply message:

SPLists Lists = Web.Lists();
foreach (spListItem folder in Lists.Folders)

Thanks to… for the insight.

And to… for showing that even though it’s a folder, it’s still an SPListItem.

And to…

And to this post, which I wish I had found two or three days ago:…

While researching this, the following post was handy:…

It wasn’t my problem, but I’m wiser for understanding a little more about SharePoint by reading it.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s