Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

.NET CSOM

Posted on 2013-11-13
1
Medium Priority
?
566 Views
Last Modified: 2013-12-11
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.
0
Comment
Question by:Isaac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 2000 total points
ID: 39647875
Hi,

sorry-have not yet had the time to prototype / verify the code, but from what I see it should be:

1. Error in your CAML query
You missed the "VIEW" root element in your string.
So instead of
query.ViewXml = "<Query><Where><Eq><FieldRef Name='ProjNumber' /><Value Type='Text'>"+proj.Text.ToString()+"</Value></Eq></Where></Query>";

Open in new window

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

Open in new window


2. Subsite
It seems that examples is a sub site and not a site collection. Therefore your code
 Web wb = site.RootWeb;

Open in new window

will simply get the site collections root web - which is "/" (in your case http://isaac.issharepoint.com/).
Please replace the above line with
Web wb = site.OpenWeb("/examples");

Open in new window


HTH
Rainer
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This collection of functions covers all the normal rounding methods of just about any numeric value.
In case you ever have to remove a faulty web part from a page , add the following to the end of the page url ?contents=1
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question