gpt4 book ai didi

c# sharepoint 如何使用其他 SPListItem 的 FIELD 值设置 SPListItem 的 FIELD 值?

转载 作者:行者123 更新时间:2023-11-30 22:13:29 27 4
gpt4 key购买 nike

我想将多个文档(文件)上传到一个 Sharepoint 文件夹中。在“ItemAdded”事件期间,我想“复制”父文件夹的 FIELDS(SPListItem) 到当前(上传的)项目。

当我检查当前项目的 FIELDS 时,它们都是已经在那了。

但是我如何才能将每个 FIELD VALUE 从文件夹项复制到上传项目?

我不知道如何从“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 的值??请帮助...

史蒂芬

最佳答案

这是一个有用的案例,我总是尝试从 Get And Set Value By Field Internal Name 获取来源

void UpdateSPListItem(SPListItem item, Model pageItem)
{
SetValueInternalName(item, "ArticleByLine", pageItem.ArticleByLine);

SetValueInternalName(item, "Comments", pageItem.Comments);

}
void SetValueInternalName(SPListItem item, string fieldInternalName, string value)
{
SPField field = item.Fields.GetFieldByInternalName(fieldInternalName);
item[field.Id] = value;
}

关于c# sharepoint 如何使用其他 SPListItem 的 FIELD 值设置 SPListItem 的 FIELD 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19136664/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com