Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

My Library Column does not exist when I execute a Caml Query

$
0
0

Hello,

I am new to SharePoint programming.  I am trying to understand how I can access the documents in a Library Folder and obtain the field values for each document in the container.  With this in mind I have pieced together the following code from various posts that demonstrate how to to this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Client;

namespace ConsoleListItemsInFolder
{
    class Program
    {
        static void Main(string[] args)
        {
            ClientContext ctx = new ClientContext("http://mwp_lenovo");
            List DocumentsList = ctx.Web.Lists.GetByTitle("Claims Documents");
            CamlQuery camlQuery = new CamlQuery();
            camlQuery = new CamlQuery();
            camlQuery.ViewXml = "<View Scope=\"RecursiveAll\"> " +
                            "<Query>" +
                            "<Where>" +
                                        "<Eq>" +
                                            "<FieldRef Name=\"FileDirRef\" />" +
                                            "<Value Type=\"Text\">/Claims Documents/11111111 Stuart Little</Value>"+
                                         "</Eq>" +
                            "</Where>" +
                            "</Query>" +
                            "</View>"; 
            ListItemCollection listItems = DocumentsList.GetItems(camlQuery);
            ctx.Load(
                listItems,
                items => items
                .Include(
                    item => item["Title"],
                    item => item["Claim Number"],
                    item => item["Policy Number"],
                    item => item["Policyholder Name"],
                    item => item["Document Type"]));
            ctx.ExecuteQuery();
            foreach (ListItem listItem in listItems)
            {
                Console.WriteLine("Title: {0}", listItem["Title"]);
                Console.WriteLine("Claim NUmber: {0}", listItem["Claim Number"]);
                Console.ReadLine();
            }


        }
    }
}

When I execute the code with the debugger ctx.ExecuteQuery(); throws the following error:

Microsoft.SharePoint.Client.ServerException was unhandled
  Message=Column 'Claim Number' does not exist. It may have been deleted by another user.  /Claims Documents
  Source=Microsoft.SharePoint.Client.Runtime
  ServerErrorCode=-2147024809
  ServerErrorTypeName=System.ArgumentException
  ServerStackTrace=""
  StackTrace:
       at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream)
       at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()
       at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
       at ConsoleListItemsInFolder.Program.Main(String[] args) in c:\Users\matt.paisley\Documents\Visual Studio 2012\Projects\ConsoleListItemsInFolder\ConsoleListItemsInFolder\Program.cs:line 37
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

These columns do exist in the Library as verified in Library Settings.  Many of the Library column names contain two words divided by a space.  Is this causing the problem?  Does SharePoint maintain a less offensive representation of the field name internally?  If so, how can I get it?

If I run this code with only the title, then it runs fine.

I Thank All in advance for any assistance that you can provided.

Regards,

Matt Paisley


Matthew Paisley


Viewing all articles
Browse latest Browse all 11571

Latest Images

Trending Articles



Latest Images

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