I am not familiar with Sharepoint and need to get data from it to use in an application using CSOM.
I'm able to connect and retrieve data for lists on the site. The problem I have is that a lot of the data I need is wrapped up in what I've been told is a "SharePoint News Feed".
Below is what I have so far but it doesn't work. listItemCollection seems to get populated (17 items) but I can't see any properties that enable me to get at the data.
How do I get data from pages in the SitePages ?
public class VacancyService : IVacancyService
{
private readonly ISiteCredentialService _siteCredentialService;
private const string SharePointSiteUrl = "https://[my].sharepoint.com/vacancies/";
public VacancyService(ISiteCredentialService siteCredentialService)
{
_siteCredentialService = siteCredentialService;
}
public List<VacancyDto> GetData()
{
List<VacancyDto> result = new List<VacancyDto>();
using (var context = new ClientContext(SharePointSiteUrl))
{
context.Credentials = _siteCredentialService.GetSharepointOnlineCredentials();
// Assume the web has a list named "Vacancys".
var listTitle = "Site Pages";
List list = context.Web.Lists.GetByTitle(listTitle);
context.Load(list);
CamlQuery cQuery = new CamlQuery();
ListItemCollection listItemCollection = list.GetItems(cQuery);
context.Load(listItemCollection, items => items.Include(item => item));
context.ExecuteQuery();
foreach (ListItem listItem in listItemCollection)
{
string itemTitle = listItem.GetFieldValueString("Title");
VacancyDto dto = new VacancyDto()
{
Title = itemTitle
};
result.Add(dto);
}
}
return result;
}
}