0

I know how to get one list from SP in my web-application, but I want to display 2 lists that I have in 2 div's. My problem is that Everything disappears when i run them with the code below:

var sList = subWeb.Lists.GetByTitle(subWeb.Title + "list1" + "list2");

It seems that the code to actually get both the lists work separately. Any ideas on how I get both of them? I appreciate all tips. Full code below

    {
    public ActionResult Index()
    {
        using (ClientContext context = new ClientContext("https://abct.sharepoint.com/"))
        {
            SecureString password = new SecureString();
            string strPassword = "...";
            foreach (var c in strPassword.ToCharArray()) password.AppendChar(c);


            Web web = context.Web;
            context.Load(web, w => w.Title);
            context.ExecuteQuery();

                          ViewBag.Title = web.Title;
        }

        return View();
    }

    public ActionResult Society()
    {
        var municipals = new List<Municipal>();

        using (ClientContext context = new ClientContext("https://abc.sharepoint.com/"))
        {
                            SecureString password = new SecureString();
            string strPassword = "...";
            foreach (var c in strPassword.ToCharArray()) password.AppendChar(c);

                            SharePointOnlineCredentials credential = new SharePointOnlineCredentials("...", password);
            context.Credentials = credential;

            var subWebs = context.Web.Webs;
            context.Load(subWebs, webs => webs.Include(web => web.Title));
            context.ExecuteQuery();

            foreach (var subWeb in subWebs)
            {

                var sList = subWeb.Lists.GetByTitle(subWeb.Title + "Societies" + "Committee");

                context.Load(sList);
                try
                {
                    context.ExecuteQuery();
                }
                catch
                {
                    continue;
                }

                CamlQuery query = CamlQuery.CreateAllItemsQuery();
                var listItems = sList.GetItems(query);
                context.Load(listItems, items =>
                items.Include(item => item["F_x00f6_reningsnamn"], item => item["Idrott"],
                item => item["LinkTitle"], item => item["Funktion"], item => item["Telefon"]));

                context.ExecuteQuery();

                var societies = new List<Society>();
                foreach (var item in listItems)
                {
                    var society = new Society
                    {
                        Name = item["F_x00f6_reningsnamn"].ToString(),
                        Sport = item["Idrott"].ToString(),
                        ContactN = item["LinkTitle"].ToString(),
                        Role = item["Funktion"].ToString(),
                        PhoneN = item["Telefon"].ToString()
                    };
                    societies.Add(society);
                }

                var municipal = new Municipal
                {
                    Name = subWeb.Title,
                    Societies = societies
                };

                municipals.Add(municipal);
            }
            return View(municipals);
        }
    }
  • Get the lists in two separate calls. – Bunzab Nov 9 '15 at 12:58
  • Ok, and copy Everything? – Sanna Wahlén Nov 9 '15 at 13:01
  • Your code looks incomplete. Can you please post full.. – Asad Refai Nov 9 '15 at 13:02
  • That's up to you. Ideally only retrieve what you need by refining your CAML queries. – Bunzab Nov 9 '15 at 13:03
  • This is an MVC question that should be asked in StackOverflow. Though, to answer your question, you should have two partial views. Place the two partials on the one view, each partial view with an action that retrieves one of the lists. – wjervis Nov 9 '15 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.