Solved

.NET CSOM

Posted on 2013-11-13
1
562 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 500 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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
When using a search centre, I'm going to show you how to configure Sharepoint's search to only return results from the current site collection. Very useful when using Office 365 with multiple site collections.
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

728 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