List items - Key value pairs RRS feed

  • Question

  • Hello,

    I need to get all list items and store it in a key value pair. where Key should be my input parameter and value should be list object. This dictionary(?) available globally in my solution. where I pass the key input and get the value (list) object and access its values like value.ID(which is a list id). Hope this is clear.

    Please help



    Monday, October 1, 2012 8:27 PM

All replies

  • hi Alex,

    you can surely create dictionary as you like.

    Dictionary<Int, ListItem> ListItemData = new Dictionary<Int, ListItem>();

    Thanks and Regards, Shailesh B. Davara

    • Proposed as answer by Anand . Ramanan Tuesday, October 2, 2012 3:26 PM
    • Unproposed as answer by AlexMathew Tuesday, October 2, 2012 4:20 PM
    Tuesday, October 2, 2012 5:39 AM
  • Hi shailesh,

    THanks for the reply.

    I need complete code snippet to achieve my functionality. May be my idea was wrong. all that I need is to setup Lookup column and get values .


    Tuesday, October 2, 2012 2:49 PM
  • Take a look at this http://stackoverflow.com/questions/2551177/how-to-get-all-possible-values-for-spfieldlookup

    Essentially what you are searing for is to "get lookup values from SharePoint"  that should give you results that show you ways of retrieving this information. From that point take the example from Shailesh, loop through your SPFieldValuecollection and add it to your dictionary.


    Tuesday, October 2, 2012 3:27 PM
  • Hi Froodien1,

    Thanks for your reply!

    I think, I am confused. Ok, my requirement is below example.

    I have a list called "Types" (This list is pre polulated / already exist in SharePoint). contains ID, Type fields. Values are

    ID Type

    1   A

    2   B

    3   U


    I have another list called "Quantity" (Empty list). fields are ID, QTY, TYPE(look up to above list). This list data is coming from x location. Original Values are


    1    90   A

    2     5    U

    Now, I have write console app to populate this list "Quantity". where the TYPE fields should populate with the ID column of TYPEs list

    My Quantity List in SharePoint should look like this


    1    90    1

    2     5     3

    Hope this clear. Sorry, If I confused you with my question. Appreciate your time answering my question. Looking forward.



    Tuesday, October 2, 2012 3:55 PM
  • In your quantity list when you are adding the lookup column there is an option to pull in other columns as well and you can choose the ID column there.


    This will add the lookup value and the ID as columns and you can adjust your view to show the columns you finally need.


    • Proposed as answer by Mano Mangaldas Wednesday, October 3, 2012 12:12 PM
    • Unproposed as answer by AlexMathew Wednesday, October 3, 2012 4:30 PM
    Wednesday, October 3, 2012 8:55 AM
  • I need to achieve this through code. Not through wizard. I already know how to do with wizard. All I am trying here is do using c# code and sharepoint list web service.
    Wednesday, October 3, 2012 4:30 PM