The CAML Query does not support group by object collection. The other workaround is to get the object and group by LINQ query
try
{
using (SPSite oSiteCollection = new SPSite(webUrl))
{
using (SPWeb oWebsite = oSiteCollection.OpenWeb())
{
SPList listName = oWebsite.Lists.TryGetList("MCS");
if (listName != null)
{
SPView myView = listName.Views["GroupBy"];
if (myView != null)
{
SPQuery qry = new SPQuery(myView);
SPListItemCollection myItemsList = listName.GetItems(qry);
var results = (from SPListItem item in myItemsList
group item by item["Group Number"]
into grp
select new
{
GroupID = grp.Key.ToString(),
ListItemsData = grp
});
foreach (var listData in results)
{
MessageBox.Show(listData.GroupID);
foreach (var item in listData.ListItemsData)
{
MessageBox.Show(item["XmlText"].ToString());
}
}
}
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Excellent Sir! Thanks for sharing