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.
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.
Have you try Loading DropOffItems
without using Include()
?
精彩评论