0

I'm face to a strange issue. I get an splistitem with a caml query ->that's ok and validated with caml query builder.

After that, i'm try to get the title or any other meta of the item.

Here is how i have the splistitem

SPListItem item = null;
        try
        {
            SPQuery query = new SPQuery();
            query.Query = "<Where><Eq><FieldRef Name='" + _searchedField + "'/><Value Type='Text'>" + _searchedValue + "</Value></Eq></Where>";
            query.RowLimit = 1;
            foreach (string s in _viewField)
            {
                query.ViewFields += "<FieldRef Name='"+s+"' />";
            }
            SPList list = _web.Lists[_listLookup];
            item = list.GetItems(query).Cast<SPListItem>().First();

            //item = list.GetItemById(item.ID);
            //SPListItemCollection items = list.GetItems(query);
            //if (items.Count > 0)
            //    item = items[0];
        }
        catch (Exception ex)
        {
            //diagnosticsService.WriteTrace(0, new SPDiagnosticsCategory("BU Finance", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, "generateTree = " + ex.Message + "--" + ex.StackTrace);
        }
        return item;

And then i try to get the value and always i get back {Title} or the name of meta

_item.Fields.GetFieldByInternalName("Title");
item.Fields["Title"];
4

You are getting the field, not it's value.

To get the value use this:

item["Title"]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.