Avatar of Isaac
Isaac
Flag for United States of America asked on

.NET CSOM

1)  I created the below windows form and .NET Managed client object code.  It is supposed to retrieve items from a “Projects” list based on my CAML query and render the returned items into a listbox.  It works fine but everything gets returned.  The filter is not really working.  Any ideas?  
Here’s my form:  
Form
Code:
using (ClientContext ctx = new ClientContext("http://isaac.issharepoint.com/examples/"))
            {
                ctx.Credentials = new NetworkCredential("guest1", "xxxxxx#", "Sharepointroad");
                Site site = ctx.Site; //Loads site collection into the site object
                ctx.Load(site);

                Web wb = site.RootWeb;
                ctx.Load(wb);

                ctx.ExecuteQuery(); //Go to the server and run all that has been loaded

                //listBox1.Items.Add(ctx.Url);
                //listBox1.Items.Add(site.Url);

                List lst = wb.Lists.GetByTitle("Projects");
                ctx.Load(lst);

                ctx.ExecuteQuery();
                listBox1.Items.Add(lst.Title);

                CamlQuery query = new CamlQuery();
                query.ViewXml = "<Query><Where><Eq><FieldRef Name='ProjNumber' /><Value Type='Text'>"+proj.Text.ToString()+"</Value></Eq></Where></Query>";

                ListItemCollection all = lst.GetItems(query);
                ctx.Load(all);
                ctx.ExecuteQuery();

                foreach (ListItem myList in all)
                {
                    listBox1.Items.Add("Project Number: " + myList["ProjNumber"]);
                    listBox1.Items.Add("       Amount Projected: " + myList["AmtProjected"]);
                    listBox1.Items.Add("       Fiscal Year: "+myList["FiscalYear"]);
                }
            }

Open in new window


2)  How do I change “Web wb = site.RootWeb;” to really point to http://isaac.issharepoint.com/examples/.
I don’t want the root level “Projects” list.  I want the “Projects” in the “examples” site.  Yesterday, I kept getting an error and it went away when I created a “Projects” list at site collection level which is not the list I want.

Any ideas?  Thanks for any help you can provide.
Microsoft DevelopmentMicrosoft SharePointMicrosoft Applications

Avatar of undefined
Last Comment
Rainer Jeschor

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Rainer Jeschor

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck