Я хочу загрузить Mulitple Documents (Files) в папку Sharepoint FOLDER. Во время события «ItemAdded» я хочу «скопировать» FIELDS родительской папки (SPListItem) в текущий (загруженный) элемент.C# sharepoint Как установить значение FIELD для SPListItem с FIELD Value из другого SPListItem?
Когда я проверяю FIELDS текущего элемента, все они уже есть .
Но КАК Я могу скопировать каждое ПОЛЕВОЕ ЗНАЧЕНИЕ из пункта папки в загруженный товар ?
Я не знаю, как зачитать значения полей из «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();
Этот код выше не работает, он всегда даёт сообщение «поле уже существует» Как я могу зачитывает ЗНАЧЕНИЕ ПОЛЯ? Я расстроен, нет способа узнать значение поля? Пожалуйста, помогите ...
Штеффен
Спасибо, я попробую это –
Можете ли вы написать код больше «IF THEN ELSE» Синтаксис? Я не понимаю "?" и ":" синтаксис .... :) –
string stringFieldValue = string.Empty; если (sourceItem [internalFieldName]! = NULL) { stringFieldValue = CurrentItem [internalFieldName] .ToString()» } еще { stringFieldValue = string.Empty; } – zchpit