Working with SharePoint’s Discussion Lists Programmatically – Part 1

2 במאי 2010

תגיות: ,
17 תגובות

This is part of a series of posts about Working with Discussion lists programmatically: Part 1(This one), Part 2, Part 3.

I am currently involved in a project that requires a programmatic way to query a discussion list for it’s data, and create new items in it.
As it turns out, SharePoint discussion lists are not so ordinary lists. They have a very complex structure to store it’s data.

I came across several resources that helped me figure out how this whole thing works, and they are listed at the end of this post. This post is the summary of what I learned, and an more dated version that apply to SP 2010.

Before we get into code, lets try to understand how those lists are organized.

Content types

If you take a look at a discussion list’s settings page, you will see that it uses tow different content types: Discussion, and Message.

Discussion list’s content types

Discussions are new threads that are opened by users. I refer to them generally as Topics.
Messages are the responses posted at a topic. I refer to them generally as Replies.

If you follow the content types hierarchy, you will see that Topics are actually Folders.

Discussion is a Folder

So every topic you open, is in fact a folder, and the replies to that topic are list items stored in that folder.


So we know how topics are stored, and how to get to replies in them. Once we got the list of replies of a specific topic, how would we know which reply is for which?

Take this conversation for example:

A sample conversation

If we will try to get all the reply for the topic “I have a question”’, we will get a flat list of all the replies. But what if we wanted to build a tree representation like it was originally? We need a way to tell for each reply object, what it was a reply for.

Here comes the threading attribute. Each reply has a hidden column called “Threading” (there are other columns as well that contains the same data).

The threading attribute

This column stores a chained string that represent the depth of this item in the tree of replies. Each time we add a new reply down the tree, that reply get’s the parent reply’s threading string, appended with some other new string.

discussions_4b  The threading value of messages

As you can see, the threading of the reply “I know the answer” has the same length of “The answer is 42”, because they are at the same level. But threading of “LOL” is a bit longer, because it was a reply to “The answer is 42”.

So to wrap it up:

  • If you look at a certain threading string, you can tell it’s depth by it’s length.
  • You can get the correct order of replies, if you just sort by the Threading column.


We now have the understanding for how to build something like the default views of a discussion list.

The default view for a discussion list shows all the topics.

 discussions_5 Discussion list’s default view

To recreate this view we need to get the folders in the list.
Actually, folders are actually list items, so it’s sufficient to get the root level list items. Some times I will prefer this method.

The Flat view just shows all the replies for a selected topics without any indentation.

Discussion list’s flat view

To recreate this view, we need to get all the items in the designated folder, and print them as a list.

The Threaded view also shows replies for a selected topic, but in a hieratical way that takes care of indentation.

Discussion list’s threaded view

To recreate this view, we need to get all the items in the designated folder. Once we have them we will sort the list based the threaded column. To add correct indentation, we can right-pad each item based on the length of the threaded value. Let take for example the first reply – “I know the answer”. It’s thread value is:


The length is 57. So we can add 57px of right padding(If you want smaller padding you can do some kind of calculation based on the length).

This will create the tree looking structure.


In this post we learned how SharePoint’s discussion lists work. We now have the tools to recreate the basic functionality of a discussion list. This is what I’m going to do in the following posts.

In the making of this post I have used the following posts.

הוסף תגובה
facebook linkedin twitter email

כתיבת תגובה

האימייל לא יוצג באתר. שדות החובה מסומנים *

17 תגובות

  1. Brizky5 במאי 2010 ב 17:34

    I've been lookin for days to figure out why, when linking to our Discussion Board via Access, the table looks so not what I expected. Thanks for clarifying what's going on with a Discussion. But my question is where are these folders that represent a Discussion? Trying to create an MS Access report that incorporates discussions and all replies for each discussion. I'm so close to victory I can taste it. Thanks again.


  2. Itay Shakury5 במאי 2010 ב 22:21

    Hi Brizk,
    What do you mean "where are these folders"?
    There are right there at the root of the folder, they are just disguised as topics.

  3. Hugo Marques27 באפריל 2011 ב 18:34

    Just want to let you know that your article is great! Congratulations, it helped me a lot. Thank you and keep up the good work!

  4. Anne7 בנובמבר 2011 ב 18:42

    Great post – saved me loads to time trying to work out how to have a mandatory field on the initial post but not on subsequent replies. Sorted!

  5. scierione12 באפריל 2012 ב 5:57

    Hi !
    Congratulations on the blessing that you are receiving!

  6. Leamstuts10 במאי 2012 ב 1:58

    Show one's gratitude you very much in regard to the take forum. I well-trained a lot and got to understand the lucid with attractive people. I'll be a frequent visitor.

  7. choroshin14 במאי 2012 ב 15:18

    Great post!!!

  8. Niko Holmen28 במאי 2012 ב 15:05

    would it be possible to translate your web-site into spanish because i have difficulties of speaking to english, and as there usually are not numerous pictures in your internet site i’d prefer to go through a fantastic of what you may be writting

  9. bibedswaild12 ביולי 2012 ב 3:31

    Un compte quitiré la sup?priméprofil : doctinaute d'orposté le puis j'aimerai communiqué avec système de non modèle : cyriaque délivre nousdes sectes contente pas de faire le second s?inscrit il localisation: marlysujet: saint jeu : pour nous en juin merci pour ce accessoires téléphonette description je souhaite salut regarde de toute façon ce accessoires téléphone plaisir de vous répondre de lui faire évaluer l'interprétation et la modificationaprès lien vers ce accessoires téléphone topic dans des classeurs.

  10. bags17 בספטמבר 2012 ב 14:58

    Oh my goodness! a tremendous article dude. Thanks However I'm experiencing concern with ur rss . Don't know why Unable to subscribe to it. Is there anyone getting equivalent rss downside? Anybody who knows kindly respond. Thnkx.

  11. icon collection22 בספטמבר 2012 ב 11:04

    Completely I share your opinion. I think, what is it good idea.

    P.S. Please review Android Tab Icons from yourmailkept

  12. unlabball28 באוקטובר 2012 ב 9:09

    That stop of Skelton against the Cardinals on Sunday during a 21-14 victory that improved the Vikings to 5-2 was the perfect examples just mes practice for the first time in training camp, and when asked whether the Packers And if you are serious in winning and if your heart is in it, then you will probably win
    Or if he is still playing at the same level Stats if you would prefer to call it Sometimes the legs feel a little heavy, but I feel great," Winfield said

  13. Foote13 בדצמבר 2012 ב 22:30

    This post is priceless. How can I find out more?

  14. Gustafson16 בדצמבר 2012 ב 8:18

    Very good post! We are linking to this particularly
    great post on our site. Keep up the great writing.

  15. Asheesh5 בפברואר 2013 ב 13:54

    Hi I want to Know if We can find out the Parent ID of the Reply .
    Not the Parent ID of the Discussion Item but ID of the Immediate Parent.

  16. Broyles28 בפברואר 2013 ב 0:01

    What's up, I check your blogs daily. Your story-telling style is witty, keep up the good work!

  17. Tate26 במרץ 2013 ב 18:05

    Because the admin of this web page is working, no doubt very quickly it will be famous, due to its feature contents.