0

请帮忙,

我正在尝试将 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();

它不起作用,因为它总是说所有字段都已经存在!你能帮我吗,我做错了什么?

史蒂芬

4

1 回答 1

1

您不能将字段添加到 SPListItem。ListItem 已经包含您将文件上传到的列表中存在的所有字段。相反,如果您想设置字段的值,您可以使用字段的内部名称来执行此操作:

currentItem["InternalNameOfField"] = "I am the new value";

更多信息和示例可以在MSDN上找到

于 2013-10-01T13:55:50.663 回答