Solved

How to retrieve SharePoint Discussion Board replies and other information programmatically in C# code?

Posted on 2012-04-06
5
3,636 Views
Last Modified: 2012-04-11
Hi, I have one discussion board name is PBG, user have posted some topic/subject and other users replied on those topic/subject.

Now I want to retrieve the information who replied (user login/display name) on which date topic wise.

I write below code to get all the topic/subject in that Discussion Board:
--------------------------------------------------------------------------------------------------------------------------------------
mySite = SPContext.Current.Site;
myWeb = mySite.OpenWeb();
SPList discussion_list = myWeb.Lists["PBG"];
DataTable dt = discussion_list.Folders.GetDataTable();
GridView1.DataSource = dt;
GridView1.DataBind();

Please share the code to retrieve information about users who replied and replied data with topic wise.
Thanks.
0
Comment
Question by:Minesh Shah
  • 3
  • 2
5 Comments
 
LVL 31

Accepted Solution

by:
Jamie McAllister MVP earned 500 total points
ID: 37818540
0
 
LVL 10

Author Comment

by:Minesh Shah
ID: 37832086
Hi, thanks for sharing MSDN thread, I have written below code to get all topic/subject:
----------------------------------------------------------
mySite = SPContext.Current.Site;
myWeb = mySite.OpenWeb();
SPList discussion_list = myWeb.Lists["PBG"];
foreach (SPListItem folder in discussion_list.Folders)
{
Response.Write("Item Name: " + folder.Name + "<BR>");
Response.Write("Item ID: " + folder.ID + "<BR>");
Response.Write("Author: " + folder["Author"].ToString() + "<BR>");
Response.Write("Posted Date: " + folder["Created"].ToString() + "<BR>");
}
//----------------------------------------------------
But still I am not able to retrieve the replies information of each topic/subject means who replied and replied date because the code
 7) Loop through all discussion replies:
foreach (SPListItem listItem in myDiscussionList.Items)// not working giving error that “Unable to cast object of type 'Microsoft.SharePoint.SPList' to type 'Microsoft.SharePoint.SPListItem'.”
{
}
,
can you please share the code how to get replies information?
0
 
LVL 31

Expert Comment

by:Jamie McAllister MVP
ID: 37832126
The implication of the error message is that myDiscussionList.Items is returning a SPList rather than a SPListItemCollection. I'd find that very unlikely.

Can you step through the code and confirm this please?
0
 
LVL 31

Expert Comment

by:Jamie McAllister MVP
ID: 37832132
Alernatively, post your full code and I'll replicate it in my Sandbox later.
0
 
LVL 10

Author Closing Comment

by:Minesh Shah
ID: 37833982
thanks now it's working.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

For SharePoint sites, particularly public-facing ones, there are times when adding JavaScript, Meta Tags, CSS Styles or other content to the page <head> section is more practical than modifying master pages.  For instance, you could add the jQuery l…
Summary In SharePoint 2010 it is easy to create custom color themes to jazz up a site. Theme colors can also be created in PowerPoint 2010 with a few clicks. But how do the chosen colors actually look in the SharePoint site? The attached PowerPoint…
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now