簡體   English   中英

如何在SharePoint中讀取具有多個值的LookUp字段?

[英]How do I read LookUp fields with multiple values in SharePoint?

嗨,謝謝你的期待!

背景

我繼承了一個基於SharePoint 2007的舊.NET項目,並設計了外部核心庫,只訪問SP數據,因此SP只是一個后端。 是的,我知道遷移到SQL會更好,但客戶端不同意。

以前的開發人員使用簡單的read方法來讀取SP列表中的數據:

  SPList list = CurrentRootWeb.Lists["SomeListName"];

然后他們通過排序字典訪問列表屬性(即列表中的每個項目,獲取項目[“SomeValue”])。

我不熟悉SharePoint,因此我不知道這是否是訪問其數據的最有效方式。

問題

如何在SharePoint中讀取具有多個值的LookUp字段?

他們要求的每個屬性似乎都需要一個字符串作為回報。 所以item[SomeString]沒關系,但是item[SomeList]讓一切都item[SomeList] 我原以為多值查找列表列是一個包含選定值的序列化或分隔字符串(例如:“red; blue; green”)。 我錯過了什么?

謝謝!

如果您對具有多個值的LookUp字段特別感興趣,而不僅僅是MultiChoice feilds,那么以下代碼應該有所幫助:

item.Fields["LookFieldName"].Type == SPFieldType.Lookup;
SPFieldLookup LookUpField = item.Fields["LookFieldName"] as SPFieldLookup;
if (LookUpField.AllowMultipleValues)
{
    SPFieldLookupValueCollection valueCollection = item[Field.Id] as SPFieldLookupValueCollection;

    string[] arrLookupValues = (from SPFieldLookupValue val in valueCollection select val.LookupValue).ToArray<string>();


 }

對於列表字段中的每個SPField ,您需要測試字段的Type

如果類型為SPFieldType.MultiChoice ,則將SPField SPFieldType.MultiChoiceSPFieldChoice並訪問Choices集合,即StringCollection

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM