简体   繁体   中英

Sharepoint SPListItem retrieve column index by name

Is it possible to retrieve the column index by name for the sharepoint SPListItem? I haven't been able to find a method for doing this.

So for example.

SPListItem data;
int32 value = data.getIndexByName("Title");

You could write extension method

public static class SPListItemExtension
{
    public static int getIndexByName(this SPListItem item, string name)
    {
        for (int i = 0; i < item.Fields.Count; i++)
        {
            if (item.Fields[i].InternalName.Equals(name))
            {
                return i;
            }

        }
        return -1;
    }

}

but, why do you want to do this?

What do you mean by the term ID in this context?

Each field will be copied from the entire SiteContentType or the SiteFields to the list itself. By copying the field each field will receive a new ID. You can query a List or the Web by using the FieldID or by using the Internal Name of a field.

var field = myList.Fields[SPBuiltInFields.Title];
Console.WriteLine(field.ID);

Hope that's what you're lookin for.

Thorsten

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM