Retrieve content type columns values in C#

596 views Asked by At

I have a document library content type with multiple columns in Sharepoint2010. I would like to retrieve the values in the column by using the following code but fails.

            objCurrentWeb = SPContext.Current.Web;
            objList = objCurrentWeb.Lists["MyNewLists"];

            foreach (SPListItem objListItem in objList.Items)

            {
                   id = (objListItem["ApplicationId"]).toString();

            }

How do I retrieve the values in my content type columns correctly?

Thank you!

1

There are 1 answers

0
Sergey Borisenko On

It can fail in two cases: 1) There is no such a field "ApplicationId". Ensure you use field internal name 2) (objListItem["ApplicationId"]) is null, so it fails with NullReferenceException on casting to string.