共享点字段尚未在C#中初始化 [英] Sharepoint field has not been initialized in C#

查看:134
本文介绍了共享点字段尚未在C#中初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个代码,它将遍历一个共享点列表中的每个列表项,并寻找一个空字段.如果发现空白字段,则会通过电子邮件通知负责列表项的人员.

I'm writing a code that will go through every list item in a sharepoint list and look for an empty field. If an empty field is found, the person responsible for the list item is notified by email.

我在val = oListItem[field.Title];行指出

该属性或字段尚未初始化.尚未请求或尚未执行请求.可能需要明确要求.

The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.

在我看来,我已经初始化了该行之前的所有内容.

It seems to me that I have initialized everything before that line.

static void Main()
{
    ClientContext context    = new ClientContext("https://****");
    context.Credentials      = new NetworkCredential("****", "****");
    List oList               = context.Web.Lists.GetByTitle("TestBI");
    FieldCollection fieldcol = oList.Fields;

    context.Load(oList);
    context.Load(fieldcol);
    context.ExecuteQuery();

    ListItem oListItem = oList.GetItemById(1);
    object val = null;

    for (int i = 1; i <= 4; i++)
    {
        oListItem = oList.GetItemById(i);
        foreach (Field field in fieldcol)
        {
            val = oListItem[field.Title];
            if(val == null)
            {
                //Send e-mail
            }
        }
    }
    context.ExecuteQuery();
}

推荐答案

欢迎使用SharePoint CSOM地狱.

Welcome to SharePoint CSOM hell.

您确实加载了List和FieldCollection,但是还必须加载每个Field.实际上,您必须加载要从中获取属性的每个SharePoint对象.

You did load your List and FieldCollection, but you also have to load each Field. In fact, you have to load every SharePoint object from which you intend to get properties.

for (int i = 1; i <= 4; i++)
{
    oListItem = oList.GetItemById(i);

    foreach (Field field in fieldcol)
    {
        context.Load(field);
        context.ExecuteQuery();
        val = oListItem[field.Title];
        if(val == null)
        {
            //Send e-mail
        }
    }
}

这篇关于共享点字段尚未在C#中初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆