以编程方式创建列 [英] Create column programmatically

查看:57
本文介绍了以编程方式创建列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式创建一行文本列?我尝试了以下有效的方法:

How to create a single line of text column programmatically ? I tried the below, which works:

 string filedNAme = Mylist.Fields.Add("My Unit", SPFieldType.Text, true);


我想为该字段使用静态名称/名称.


I want to use the static name / name for the field.

该字段的显示名称是我的单位".我也想保留内部名称-内部名称"AmyUnit"

The display name of the field is "My Unit". I want to keep the internal name as well - Internal Name "AmyUnit"

如何以编程方式创建字段时添加内部名称,显示名称.我知道使用elements.xml(站点列),但是想以编程方式创建它.如何实现此目的

How to add internal name, display name while creating a field programmatically. I am aware of using elements.xml (site column), but want to create it programmatically. How to achieve this

推荐答案

在这里找到解决方案:

 private  void AppendNewFieldToListIfNonExistsent(SPList list, string internalName,  string displayName, SPFieldType fieldType)
        {
            if (list.Fields.ContainsField(internalName)) return;

            else
            {
                list.Fields.Add(internalName, fieldType, false);

                var field = list.Fields.GetFieldByInternalName(internalName);
                field.Title = displayName;
                field.Update();

                var view = list.DefaultView;
                if (view.ViewFields.Exists(field.InternalName)) return;
                view.ViewFields.Add(field.InternalName);
                view.Update();
                list.Update();
            }
        }

以上内容摘自 https://sharepoint.stackexchange.com/questions/47007/add-various-fields-in-a-sharepoint-list-programmatically

The above is taken from https://sharepoint.stackexchange.com/questions/47007/add-various-fields-in-a-sharepoint-list-programmatically

感谢


这篇关于以编程方式创建列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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