Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I got one custom boolean column/field which I want to check if it exists or not before checking its value, currently I am using this code but it ain't working like it should,

    using (SPWeb web = properties.OpenWeb())
    {
        SPList list = web.Lists["List Name"];

        foreach (SPListItem listItem in list.Items)
        {
            if (listItem.Properties["Boolean Property"] != null &&
                    bool.Parse(listItem.Properties["Boolean Property"].ToString()) == false)
            {
                //continue
            }
            else
            {
                i++;
            }
        }
    }

I am using .Net framework 3.5 so can't use fieldexsist property.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

listItem.Properties will show metadata properties, not fields. Not sure which one you want.

I use the following to check if a field exists:

list.Fields.ContainsField("fieldname")

Likewise, for metadata properties you can use:

listItem.Properties.ContainsKey("property name")
share|improve this answer

Your Answer

 
discard

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.