开发者

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开发者_如何学JAVA;
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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜