Progamatically iterate throught discussion board and read post ,replies CSOM (client side object model )
code:
Get all posts :
ClientContext ctx = new ClientContext("http://h8.net/sites/abcd");
//Get the Discussion list
List lst = ctx.Web.Lists.GetByTitle("Discussions List");
//Get the topics in the list
CamlQuery q = CamlQuery.CreateAllFoldersQuery();
ListItemCollection topics = lst.GetItems(q);
ctx.Load(topics);
ctx.ExecuteQuery();
Get repiles:
//Select a topic from topic array . its in decending order the oldest is 0
ListItem topic = topics[0];
//Get the replies of the selected topic
q = CamlQuery.CreateAllItemsQuery(100, "Title", "FileRef", "Body");
//FileRef contains the site relative path to the folder
q.FolderServerRelativeUrl = topic["FileRef"].ToString();
ListItemCollection replies = lst.GetItems(q);
ctx.Load(replies);
ctx.ExecuteQuery();
Create Discussion ites:
ClientContext ctx = new ClientContext("http://h8.net/sites/abcd");
//Get the Discussion list
List lst = ctx.Web.Lists.GetByTitle("Discussions List");
//Create the topic
ListItem t = Microsoft.SharePoint.Client.Utilities.Utility.CreateNewDiscussion(ctx, lst, "Creted by Client OM");
t["Body"] = "This is the body";
t.Update();
ctx.ExecuteQuery();
Create a reply :
ListItem t = topics[0];
//Create the reply
ListItem r = Microsoft.SharePoint.Client.Utilities.Utility.CreateNewDiscussionReply(ctx, t);
r["Body"] = "This is the reply body";
r.Update();
ctx.ExecuteQuery();
Credit @itaysk
Metalogix Exception thrown: Server was unable to process request. ---> Value does not fall within the expected range. Solution : Look for app pool .Is posible reset iis .
Comments
Post a Comment