我想将多个文档(文件)上传到 Sharepoint 文件夹中。在“ItemAdded”事件期间,我想将父文件夹 (SPListItem) 的字段“复制”到当前(上传的)项目。
当我检查当前项目的字段时,它们都已经存在了。
但是如何将文件夹项目中的每个字段值复制到上传的项目?
我不知道如何从“ItemSource”中读出字段的值
SPList currentList = properties.List;
SPDocumentLibrary oDocumentLibrary = (SPDocumentLibrary)currentList;
SPListItemCollection collListItems = oDocumentLibrary.Items;
int AnzahlItems = collListItems.Count;
SPFieldCollection currentListFieldItems = currentList.Fields;
int AnzahlFields = currentListFieldItems.Count;
// ---------------------------------
// Get the current Item in the List
// ---------------------------------
SPListItem currentItem = currentList.Items[AnzahlItems - 1];
SPFieldCollection currentItemFields = currentItem.Fields;
int currentItemFieldsAnzahl = currentItemFields.Count;
// -----------------------------------------------------------
// For every FIELD from Source Item ADD FIELD to Target Item
// -----------------------------------------------------------
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;
// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// Folder Item 1 --> Felder anhängen ::::::::::::::::::::::::::::
// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if (currentItem.Fields.ContainsField(FeldInternalName))
{
// The FIELD is already existing at the Target Item
}
else
{
// The FIELD is not existing at Target Item, will be added
currentItem.Fields.Add(NeuesFeld);
}
} // end for
// ----------------------------
// Save Changes at Item
// ----------------------------
currentItem.Update();
上面的代码不起作用,它总是给出消息“FIELD已经存在”我怎样才能读出FIELD的VALUE?我很沮丧,没有办法读出字段的值??请帮忙...
史蒂芬