简体   繁体   中英

SharePoint CAML Query: Value does not fall into expected range

I've created the following method in a class which is intended to fetch all items in a SharePont list and load them into my entity:

public List<ItemEntity> FetchItems(SPList list)
{
    // build the CAML query of field names that we wish to retreive
    var query = new SPQuery
        {
            ViewFields = string.Concat("<FieldRef Name='Modified' />",
                                        "<FieldRef Name='Modified By' />",
                                        "<FieldRef Name='Created' />",
                                        "<FieldRef Name='Created By' />")
        };

        SPListItemCollection items = list.GetItems(query);

        return (from SPListItem item in items
                select Load("", // item id
                            "", // content type
                            "", // display name
                            "", // name
                            "", // title
                            "", // url
                            "", // author
                            "", // editor
                            Convert.ToDateTime(item["Modified"]), // date time modified
                            item["Modified By"].ToString(), // modified by
                            Convert.ToDateTime(item["Created"]), // date time created
                            item["Created By"].ToString() // created by
                    )).ToList();
}

For some reason that I don't understand it's throwing the following error:

Value does not fall within the expected range.

I thought this could be something to do with the results returned by my CAML query, but even then I restricted it down to meta data fields (which I believe should exist on every file) and unfortunately I'm still receiving the error. Where am I going wrong?

I believe you are missing the correct internal names of some built-in fields.

Try to use:

item["Author"].ToString() instead of item["Created By"].ToString() and
item["Editor"].ToString() instead of item["Modified By"].ToString()

For a full reference of sharepoint 2010 internal field names I usually consult the following link: http://sharepointmalarkey.wordpress.com/2010/10/12/sharepoint-internal-field-names-sharepoint-2010/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM