Solved

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

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

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 32

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 32

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
In case you ever have to remove a faulty web part from a page , add the following to the end of the page url ?contents=1
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

687 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