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 http://www.tech-archive.net/Archive/SharePoint/microsoft.public.sharepoi… for the insight.

And to http://forums.msdn.microsoft.com/en-US/sharepointdevelopment/thread/4108… for showing that even though it’s a folder, it’s still an SPListItem.

And to http://nickgrattan.wordpress.com/2007/10/09/document-libraries-splist-an…

And to this post, which I wish I had found two or three days ago: http://forums.msdn.microsoft.com/en-US/sharepointdevelopment/thread/9260…

While researching this, the following post was handy: http://hristopavlov.wordpress.com/2008/06/24/content-type-is-still-in-us…

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

Advertisement

Leave a Reply

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

WordPress.com Logo

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

Facebook photo

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

Connecting to %s