我想將多個文檔(文件)上傳到Sharepoint文件夾中。 在「ItemAdded」事件期間,我想將父文件夾 (SPListItem)的FIELDS「複製」到當前(上傳的)項目。c#sharepoint如何設置SPListItem的FIELD值來自其他SPListItem的FIELD值?
當我檢查當前項目的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的VALUE? 我很沮喪沒有辦法讀出一個字段的值? 請幫助...
斯特芬
謝謝你,我會嘗試這個 –
能否請你寫的代碼更「IF THEN ELSE」語法? 我不明白「?」和「:」語法.... :) –
string stringFieldValue = string.Empty; 如果(sourceItem [internalFieldName]!= NULL){ stringFieldValue = CURRENTITEM [internalFieldName]的ToString()」 } 別的 { stringFieldValue =的String.Empty; } – zchpit