Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Most rudimentary test to read a list fails...

$
0
0

Just tossed up a new clean developer portal in O365, created an app in VS2013 Pro with the App for Sharepoint template. I've added this method that should retrieve data from a simple list in the same sharepoint site and enumerate the items in that list in a table... simple? So I thought, pretty much copy pasted code that exists as samples but I can't get it to work.

public static List<Models.KSTModel> GetKST(SharePointContext spContext)
        {
            List<Models.KSTModel> ccitems = new List<Models.KSTModel>();

            using (var clientContext = spContext.CreateUserClientContextForSPHost())
            {
                if (clientContext != null)
                {
                    //List lstKSTs = clientContext.Web.Lists.GetById(new Guid("020b3e55-abec-4e8b-aad2-5e2a38c70383"));
                    List lstKSTs = clientContext.Web.Lists.GetByTitle("Costcenters");
                    ListItemCollection lstKSTItems = lstKSTs.GetItems(CamlQuery.CreateAllItemsQuery());
                    clientContext.Load(lstKSTs);
                    clientContext.Load(lstKSTItems);
                    try {
                        clientContext.ExecuteQuery();
                        if (lstKSTItems != null)
                        {
                            foreach (ListItem lstKSTItem in lstKSTItems)
                            {
                                ccitems.Add(
                                    new Models.KSTModel { Id = lstKSTItem["Id"].ToString(), Beskrivning = lstKSTItem["Beskrivning"].ToString(), Kortnamn = lstKSTItem["Kortnamn"].ToString(), Datum = Convert.ToDateTime(lstKSTItem["Datum"]), Ansvarig = lstKSTItem["Ansvarig"].ToString() });
                            }
                        }

                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.InnerException);
                    }
                }
            }

            return ccitems;
        }

The model itself is nothing fancy, but it never gets so far as to try and populate the List<Model.KSTModel> variable...

The GetItems method of the list doesn't return anything at all. It's not null, but it also doesn't have any items. And it doesn't throw an exception either.



Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>