如何更新 SharePoint 中的选择列 [英] How to update Choice column in SharePoint

查看:48
本文介绍了如何更新 SharePoint 中的选择列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要更新选择栏.假设我的列有像A"、B"这样的值.现在我需要插入他们的新值,如C".我的以下代码不起作用.

I need update choice column. Let say my column has values like "A", "B". Now I need to insert their a new value like "C". My following code is not working.

using (SPSite site = new SPSite(siteUrl))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        web.AllowUnsafeUpdates = true;
                        var spList = web.Lists[listName];
                        SPFieldChoice spChoiceField = (SPFieldChoice)spList.Fields[fieldName];
                        spChoiceField.Choices.Add(value);
                        spChoiceField.Update();
                        spList.Update();
                        web.AllowUnsafeUpdates = false;
                        return "Field has been updated with new value: " + value;
                    }
                }

推荐答案

spChoiceField.Choices.Add(value);

通过以下更改上面的行来解决

Solved by changing above line by following

spChoiceField.AddChoice(value);

这篇关于如何更新 SharePoint 中的选择列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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