Solved

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

Posted on 2012-04-06
5
3,656 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Pimping Sharepoint 2007 without Server-Side Code Part 1 One of my biggest frustrations with Sharepoint 2007 in the corporate world is that while good-intentioned managers lock down the more interesting capabilities of Sharepoint programming in…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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

17 Experts available now in Live!

Get 1:1 Help Now