请帮忙,
我正在尝试将 FIELDS 添加到“刚刚上传”的文件中。文件被上传到一个 SPFolder 对象。我想从文件上传到文件的库或文件夹中自动添加所有字段。
第一:我从事件“ItemAdded”属性中获取库(SPList)中的所有字段:
SPList currentList = properties.List;
第二:我从 currentList 中获得所有字段的 FIELD COLLECTION:
SPFieldCollection currentListFieldItems = currentList.Fields;
第三:现在我想将每个FIELD添加到currentItem(这是刚刚上传的文件):
for (int i = 0; i < AnzahlFields; i++)
{
SPField NeuesFeld = currentListFieldItems[i];
String FeldInternalName = currentListFieldItems[i].InternalName;
String FeldName = currentListFieldItems[i].Title;
NeuesFeld.Type = currentListFieldItems[i].Type;
NeuesFeld.Required = currentListFieldItems[i].Required;
NeuesFeld.ShowInEditForm = true;
NeuesFeld.ShowInDisplayForm = true;
NeuesFeld.ShowInListSettings = true;
NeuesFeld.ShowInNewForm = true;
NeuesFeld.ShowInViewForms = true;
if (currentItem.Fields.ContainsField(FeldInternalName))
{
// The Field already exists
}
else
{
// The Field is not existing, will be added
currentItem.Fields.Add(NeuesFeld);
}
}
currentitem.update();
它不起作用,因为它总是说所有字段都已经存在!你能帮我吗,我做错了什么?
史蒂芬