以编程方式创建列 [英] Create column programmatically
问题描述
如何以编程方式创建一行文本列?我尝试了以下有效的方法:
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();
}
}
The above is taken from https://sharepoint.stackexchange.com/questions/47007/add-various-fields-in-a-sharepoint-list-programmatically
这篇关于以编程方式创建列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!