Logo
  Wednesday, September 08, 2010
Sign-In  |  Sign-Up  |  Contact Us  |  Bookmark |  RSS Feed

Select Distinct or Unique values from SharePoint List  
I was looking around for the simple way of getting unique values from SharePoint list without affecting performance too much. I have seen several ways of doing it. For example, people say that you can get all the items and then check if item exists in the array or some other collection. Another example, you can load your data into DataTable and then select unique values using DataTable method but I disciovered one very simple method for selecting Distinct Values in SharePoint called GetDistinctFieldValues. Please see snippet of code below on how to use it

SPWeb web = new SPSite("http://site").OpenWeb();
SPList objList = web.Lists["List Name"];
SPField field = objList.Fields.GetField("Field Name"); 

object[,] values;
uint numberValues = objList.GetDistinctFieldValues(field, out values); 
       

for (int i = 0; i < numberValues; i++)
    comboBox1.Items.Add(values.GetValue(0, i).ToString()); 

Print Select Distinct or Unique values from SharePoint List Bookmark Select Distinct or Unique values from SharePoint List

Related Blogs  
Database Naming Convention
Database Modeling is not an easy task. It requires good analytical sckills and a lot of hours spent
SharePoint Site Provisioning with Workflow
You can provision with the SharePoint workflows. This is the site provisioning method that I would p
TFS Workspace
TFS Workspace is a one of the new concepts introduced with Team Foundation Server. TFS Workspace is
Silverlight Programming
Silverlight is going mainstream with new version being released every year and each version bring ne
Health Monitoring in ASP.NET
There is another system that Microsoft developed for .NET Developers that is not very known but impo
Continuous Integration with TFS
Continuous Integration is a commonly accepted and aknowledged software development practice. During
More
AprMay 2009Jun
MoTuWeThFrSaSu
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567