使用caml查询添加选项

问题描述 投票:0回答:1

我正在编写一个caml查询来在sharepoint中添加列。该字段是“选择”类型。

我编写了像choice1 choice2 />这样的查询

这是一个错误,名称不能以'<'字符开头。任何人都可以帮助告诉我如何使用caml查询为字段添加选项。

提前致谢。

sharepoint-2013 caml
1个回答
0
投票

Caml Query用于过滤字段值而不是添加列,如果要在选择类型字段中添加选项,可以像这样添加AddFieldAsXml,这将涉及选择,在xml中写下所有需要的选项:

        string siteUrl = "http://sp/sites/dev";
        ClientContext clientContext = new ClientContext(siteUrl);
        clientContext.Credentials = new NetworkCredential("Administrator", "Access1", "Contoso");
        List oList = clientContext.Web.Lists.GetByTitle("DemoList1");
        Field catField = oList.Fields.AddFieldAsXml(@"
            <Field Type='Choice' DisplayName='Category' Format='Dropdown'>
                <Default>IT</Default>
                <CHOICES>
                  <CHOICE>IT</CHOICE>
                  <CHOICE>Sales</CHOICE>
                </CHOICES>
        </Field>", true, AddFieldOptions.DefaultValue);
        oList.Update();
        clientContext.ExecuteQuery();

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.