I've a site column define in choice and with two possibles values. FR NL

I'd like to retrieve this two values.

i've tested this to get the spfieldlookup but now i'm blocked to get all values:

SPFieldLookup lang = null;
            foreach (SPField f in web.Fields)
                string t = string.Empty;
                if (f.Group == "Newsletter" && f.Title.Equals("testLanguage"))
                    lang = f as SPFieldLookup;

this line doesn't work to get the field

SPFieldValue f = web.Fields["testLanguage"];

thanks for your help

  • Are you creating a lookup site column or a choice site column? – Jaime Jul 14 '14 at 13:39
  • a choice site column – user1898765 Jul 14 '14 at 13:43
  • Then you're using the wrong object. A lookup is a pointer to a value in another list. (with id/display) a choice is just a collection of string values. – Jaime Jul 14 '14 at 13:47
  • thanks for your reply but how can i cast in a collection to get all values? :-S – user1898765 Jul 14 '14 at 13:52

Anyways here's a snippet to get a choice's value list into a list

public List<string> GetInvoiceTypes(SPWeb web)
            List<string> invoiceTypes = new List<string>();

            SPFieldChoice invoiceTypeField = web.Fields.GetField(CustomSiteColumns.FIELD_FACTURA_TIPO) as SPFieldChoice;
            StringCollection choices = invoiceTypeField.Choices;
            foreach (string choice in choices)

            return invoiceTypes;

Please note that CustomSiteColumns.FIELD_FACTURA_TIPO is a constant inside my code with the field's internal name

| improve this answer | |

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.