Friday, May 13, 2011

Get Distincit values from SharePoint list

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>";
}

1 comment:

  1. http://msdn.microsoft.com/en-us/library/bb897909(v=office.12).aspx

    ReplyDelete

SharePoint AI Innovations Reach General Availability

Microsoft continues to strengthen the foundation for AI-powered workplaces with the announcement that several SharePoint AI innovations are ...