SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have two lists,

List A [Document Number, Name, Title,...] (document library)
List B [Information Number, Name, Title, Document Number] (simple list)

Now List B is getting all documents from List A as lookup column and letting user add documents name to List B specific Information Number, which can have 0, 1 or many documents.

I wonder what would be the best way to get all lookup fields values (document's name but no duplicates) that are associated with any Information Number item in a ascending order by Information Number.

For example:

List B, 

       Item A -   Document 1, Document 9, Document 3
       Item B -   DOcument 2, Document 3, Document 4, Document 5
       Item C -   Document 1, Document 5, Document 9, Document 0.8

Now the output I would like is something like this,

Document 1, Document 9, Document 3, Document 2, Document 4, Document 5, Document 0.8

Can I use CAML query or through C# code, and an example code would be appreciated.

share|improve this question
up vote 1 down vote accepted

If you use a version of .net that support LINQ you can use the Distinct function after a conversion of your value:

var collectionWithDistinctElements = oldArray.Distinct().ToArray();

otherwise you can use the hast table

var list = new HashSet<string> { };

var countItems = list.Count(); //in this case countItems=1
share|improve this answer
Your answer seems alright but I tried a different way to achieve what I wanted, thanks. – Muhammad Raja Feb 6 '13 at 14:29

I used SPQuery to get list items from both lists and then filtered the only ones I need. After I stored them in a List class and used IComparable class to sort them out accordingly.

Hope it helps if anyone else encountered same problem.

share|improve this answer
maybe this way is slowest than use a hash table (I'm not pretty sure) – Salvatore Di Fazio Feb 6 '13 at 14:39
I had to perform some additional things to documents which I couldn't do with hashset :) but it comes down to requirements. – Muhammad Raja Feb 6 '13 at 14:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.