public async Task <List <XListItem> > GetItems(string CAML) { var client = Context.GetClient(); var request = new HttpRequestMessage(); Uri siteUrl = new Uri(Context.SiteUrl); Uri getItemsUrl = new Uri(siteUrl, string.Format("/_api/web/lists/GetByTitle('{0}')/GetItems(query=@v1)?@v1={{\"ViewXml\":\"<View><Query>{1}</Query></View>\"}}", Title, CAML)); request.Method = HttpMethod.Post; request.RequestUri = getItemsUrl; List <XListItem> listItems = null; await client.SendAsync(request).ContinueWith((taskwithmsg) => { var response = taskwithmsg.Result; var responseContentTask = response.Content.ReadAsStringAsync(); responseContentTask.Wait(); string resPonseData = responseContentTask.Result; XElement element = XElement.Parse(resPonseData); listItems = element.Descendants().Where(x => x.Name.LocalName == "entry").Select( (xmlElement) => { XListItem listItem = XListItem.ParseListItem(xmlElement.ToString()); listItem.List = this; return(listItem); }).ToList(); }); return(listItems); }
public async Task <XListItem> GetItemById(int Id) { var client = Context.GetClient(); var request = new HttpRequestMessage(); Uri siteUrl = new Uri(Context.SiteUrl); Uri getListItemByIdUrl = new Uri(siteUrl, string.Format("/_api/web/lists/GetByTitle('{0}')/items({1})", Title, Id)); request.Method = HttpMethod.Get; request.RequestUri = getListItemByIdUrl; XListItem listItem = null; var result = await client.SendAsync(request).ContinueWith((taskwithmsg) => { var response = taskwithmsg.Result; var responseContentTask = response.Content.ReadAsStringAsync(); responseContentTask.Wait(); string resPonseData = responseContentTask.Result; listItem = XListItem.ParseListItem(resPonseData); listItem.List = this; return(listItem); }); return(result); }