views:

18

answers:

1

I am trying to query data from a list using client object model. Everything is working except mysteriously one particular field is not. They are all being pulled the same way (mostly) and I can go and look at the list and see that clearly there is data in the field but it is just not being returned. Is there something I am missing here? Is there some sort of different type of field setting that could cause this (this is just a text field btw)?

   HostWeb = Context.Web;
    Context.Load(HostWeb, w => w.Lists);

    //Load The Drop off box documents list
    DropOffBox = HostWeb.Lists.GetByTitle("Drop-off Box");
    Context.Load(DropOffBox);

    CamlQuery DropOffQuery = new CamlQuery();
    DropOffQuery.ViewXml = "<View><Query><OrderBy><FieldRef Name='Number' /></OrderBy></Query></View>";

    DropOffItems = DropOffBox.GetItems(DropOffQuery);
    Context.Load(DropOffItems, items => items.Include(i => i.DisplayName, i => i["ows_Modified"], i => i["Recipient"], i => i["Url"],
        i => i["Location"], i => i["Number"], i => i.Id));
    Context.ExecuteQuery();

    foreach (ListItem Item in DropOffItems)
    {
        FilerDocument Doc = new FilerDocument(Item.DisplayName, DateTime.Parse(Item["ows_Modified"].ToString()), (Item["Recipient"] ?? "").ToString(),
           Item["Url"].ToString(),Item.Id.ToString(), _serverName);

        Doc.FiledUrl = (Item["Location"] ?? "").ToString();
        Doc.Number = (Item["Number"] ?? "").ToString();

        Doc.PropertyChanged += new PropertyChangedEventHandler(Document_PropertyChanged);
        DropOffDocs.Add(Doc);
    }

The part that is failing is the "Number" field. All the other fields work fine, including location which is being accessed in the same exact way and is coming from the same contenttype.

A: 

Perhaps a silly question, but you don't mention in the OP: have you double-checked that the internal column name for the field in question is really named "Number"? The Client and Server Object Models address list fields by their internal name, not (necessarily) by the field name that is displayed.


Update: I'd recommend getting a copy of U2U's CAML Query Builder. Get the 2007 version and connect to your 2010 instance via SharePoint Web Services. It will let you generate a CAML Query for a specific list, and the convenient part is that you pick the fields you're interested in and it auto-populates the query with the internal names for you.

CBono
Unfortunately yes I've verified that I am using the correct internal name (I even changed it to something I know not to exist to verify that it throws an error when attempting to access a field that doesn't exist). The actual field name isn't number it's a rather long name that I changed for this posting to simplify what was going on.
Mark
Have you tried the CAML Query Builder yet, by chance?
CBono
I Haven't, I'm not sure how changing the CAML query should affect anything? It doesn't determine the output fields I originally had the query empty and just using a new instance without any query text with the same results. Note also that location works. Thank you for the attempts to help though! I think at this point I am moving this to a WCF service and seeing if somehow I can approach this in a different direction.
Mark
Well, I use the tool in 2 ways: 1) to generate an initial first-pass for a CAML query, 2) to debug an existing query that doesn't seem to work. Since it builds queries by talking directly to an SP List, it can sometimes flush out problems. That's all... good luck, regardless! SP can be a pain at times.
CBono

related questions