Get A SharePoint Field By Name

This piece of code demonstrates how you could return a SharePoint field by passing in the name parameter.

[csharp]

private SPField GetSharePointFieldByName(string name)
{
        SPField field = null;
        try
        {
                return this._list.Fields[name];
        }
        catch
        {
        }
        foreach (SPField field in this._list.Fields)
        {
                if (field.InternalName.Trim().ToLower() == name.Trim().ToLower())
                {
                        return field;
                }
        }
        return field;
}

[/csharp]

Share

Leave a Reply

Your email address will not be published. Required fields are marked *