Today, I accidentally saw a student asking in his post that if the problem of removing duplicate values in the List had not been solved since August (the original article), and I was also studying SharePoint Development recently, there is a exercise question exactly :)
Some may have thought about using the Group in CAML to obtain the result set, but you will find that the result set after the query is executed (that is, SPList. GetItems (SPQuery) has not changed. My attempt started from the list. Later I found that the list object has a GetDistinctFieldValues method. After verification, it can solve the select distinct function similar to that in SQL. You can use several lines of code to solve the problem, and do not need to write the code and logic for loop traversal. See the following:
1 // first determine which column (column) You want to obtain the unique value. Here, change voteBoxList to your list instance, and replace "Ticketing person" with the name of the column you want to process.
2 SPField distinctField = voteBoxList. Fields ["Winner"];
3 // prepare a two-dimensional object array as an output parameter to receive the results of the column (that is, the last non-repeated value you want)
4 object [,] distinctResult = new object [0, 10];
5 // After GetDistinctFieldValues is called, distinctResult is a non-repeated value, and resultCount is a returned value.
6 uint resultCount = voteBoxList. GetDistinctFieldValues (distinctField, out distinctResult );
7
Maybe the most common question here is why do we need to use a two-dimensional array for Loading results? I also know this problem. In addition, why is the initialization of new object [] with more than 10 results? You can also be careful, you can rest assured, in fact, [0, 0] is also good, the internal method to do the array replacement processing, initially can be installed with 30 values. In the end, there are too few wss SDK resources. As mentioned above, the GetDistinctFieldValues method SDK document is blank, and so is the online MSDN document. This cannot be explained in science.
In fact, there are many solutions to a problem. I would like to discuss it with you here. SharePoint2010 heard that Release is coming in April, because the time relationship has not been able to experience IT for the first time. I hope you will come to my blog (Ryu666's IT Park) more soon.