Im working on Sharepoint 2013 Community site template. When I manually create a discussion in discussions list liking and replying features are working fine, but when I programmatically add a dicussion in discussions list its giving the following error "Value does not fall within the expected range".
This is the C# code im using to add an item in discussions list.
using (SPSite site = new SPSite("http://site-url"))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["Discussions List"];
SPListItemCollection listItemCln = list.GetItems(list.Views["Management"]);
SPListItem item = list.Items.Add();
item["Title"] = "New Post";
item["Body"] = "Body of the post";
item.Update();
}
}
Check the following images for more information...
Is there anyone came across this issue? Please help me out to solve this problem. Thank You