0

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.

1

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> { };
list.Add("a");
list.Add("a");

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

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.

  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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