在EventReceiver上,使用c#我想要檢索列表上的Sharepoint 2010選擇字段中的所有選定值。任何人都可以建議/提供關於如何閱讀選擇字段中的所有值的代碼片段?在c#Visual Studio 2010中檢索Sharepoint選擇字段的值
謝謝
在EventReceiver上,使用c#我想要檢索列表上的Sharepoint 2010選擇字段中的所有選定值。任何人都可以建議/提供關於如何閱讀選擇字段中的所有值的代碼片段?在c#Visual Studio 2010中檢索Sharepoint選擇字段的值
謝謝
我不確定你想做什麼。如果你想獲得的所有值從列表中的字段(選擇)我可以建議你到一個對象(SPList)獲取列表,通過項目(yourSPListObject.items)
// get the current web you are in
SPWeb objWeb = SPContext.Current.Site.OpenWeb();
//get your list
SPList lstYourInfoList = objWeb.Lists["<ListNameHere"];
//Iterate through the items in the list
foreach(SPListItem item in lstYourInfoList.items){
//pick out your information needed
string choiceSelected = item["<ColumnNamethatrepresentsyourchoicefield>"].ToString();
//store your information somewhere
//store the string in a local list and pass this list back out
}
這個迭代可以幫助,如果你想獲得的所有用戶可以選擇從
http://www.mindfiresolutions.com/SharePoint-Choice-Field--Fetch-Each-Choice-Item-80.php
希望如果你有一個選擇欄,其中多個項目,可以選擇這回答您的問與答
的選擇,你可以用它來分開它們:
string values = item["yourColumn"] as string;
string[] choices = null;
if (values != null)
{
choices = values.Split(new string[] { ";#" }, StringSplitOptions.RemoveEmptyEntries);
}
看到這篇博文。這是做這件事的正確方法。 http://www.c-sharpcorner.com/Blogs/10257/
SPFieldMultiChoiceValue choices = new SPFieldMultiChoiceValue(item["MultiChoice"].ToString());
for (int i = 0; i < choices.Count; i++)
{
Console.WriteLine(choices[i]);
}
重溫我的回答後,近三年來,我看到的做法有多髒了。你應該使用@Sia的答案,這是乾淨的方式來做到這一點。 – Hinek