Solved

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

Posted on 2012-04-06
5
3,754 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

730 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