此IEnumerable仅支持单个枚举

时间:2014-11-12 13:59:23

标签: sharepoint

尝试使用分页从Sharepoint Web服务中提取一些数据,但我无法让它返回数据列表。我一直得到'返回语句中的这个IEnumberable只支持一个枚举。

    public List<UserInformationListItem> getAllUsers()
    {
        var userContextList = new List<UserInformationListItem>();
        SharepointDataContext context = new SharepointDataContext(new Uri("http://spserver/_vti_bin/ListData.svc/"));
        context.Credentials = new NetworkCredential("myusername", "mypassword");

        DataServiceQueryContinuation<UserInformationListItem> token = null;
        var response = context.UserInformationList.Execute() as QueryOperationResponse<UserInformationListItem>;

        do
        {
            if(token != null)
            {
                response = context.Execute<UserInformationListItem>(token);
                userContextList.AddRange(response);
            }
            else userContextList.AddRange(response);
        }
        while ((token = response.GetContinuation()) != null);

        return response.ToList();
    }

1 个答案:

答案 0 :(得分:0)

明显的错误,只是盯着屏幕太久了。应该已经返回userContextList而不是......

public List<UserInformationListItem> getAllUsers()
{
    var userContextList = new List<UserInformationListItem>();
    SharepointDataContext context = new SharepointDataContext(new Uri("http://spserver/_vti_bin/ListData.svc/"));
    context.Credentials = new NetworkCredential("myusername", "mypassword");

    DataServiceQueryContinuation<UserInformationListItem> token = null;
    var response = context.UserInformationList.Execute() as QueryOperationResponse<UserInformationListItem>;

    do
    {
        if(token != null)
        {
            response = context.Execute<UserInformationListItem>(token);
            userContextList.AddRange(response);
        }
        else userContextList.AddRange(response);
    }
    while ((token = response.GetContinuation()) != null);

    return userContextList.ToList();
}