Show Whether A SharePoint Field Contains Metainformation

This is a small code sample that will show you how to determine whether a SharePoint field contains meta information.

[csharp]

public static bool SharePointFieldHoldsMetaInformation(SPList list, string internalFieldName)
{
        bool containsFlag = false;
        try
        {
                if (list == null)
                {
                        return containsFlag;
                }
                SPField exampleField = list.Fields.GetFieldByInternalName(internalFieldName);
                if (exampleField == null)
                {
                        return containsFlag;
                }
                switch (exampleField.Type)
                {
                        case SPFieldType.Lookup:
                        case SPFieldType.Calculated:
                        case SPFieldType.User:
                        return true;
                }
                return false;
        }
        catch
        {
                return false;
        }
}

[/csharp]

Share

Leave a Reply

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