The GetDistinctFieldValues method can only be used for Text fields.
The following code example uses the GetDistinctFieldValues method to return a two-dimensional object array representing values from the Title field of a specified list and then iterates through the array to display unique values.
SPSite siteCollection = SPControl.GetContextSite(Context);
SPList list = siteCollection.AllWebs["Site_Name"].Lists["List_Name"];
SPField field = list.Fields["Title"];
object[,] columnItems;
uint numberValues = list.GetDistinctFieldValues(field, out columnItems);
for (int i=0; i<numberValues; i++)
{
string uniqValue = SPEncode.HtmlEncode(columnItems.GetValue(0, i).ToString());
Label1.Text += uniqValue + "<BR>";
}
The following code example uses the GetDistinctFieldValues method to return a two-dimensional object array representing values from the Title field of a specified list and then iterates through the array to display unique values.
SPSite siteCollection = SPControl.GetContextSite(Context);
SPList list = siteCollection.AllWebs["Site_Name"].Lists["List_Name"];
SPField field = list.Fields["Title"];
object[,] columnItems;
uint numberValues = list.GetDistinctFieldValues(field, out columnItems);
for (int i=0; i<numberValues; i++)
{
string uniqValue = SPEncode.HtmlEncode(columnItems.GetValue(0, i).ToString());
Label1.Text += uniqValue + "<BR>";
}
http://msdn.microsoft.com/en-us/library/bb897909(v=office.12).aspx
ReplyDelete