Zum Hauptinhalt wechseln

Wiki

Startet die Suche
Home
Blog
Developments
FAQ
Wiki
Sonstiges
Kontakt
Suche
Impressum
  
Hezser.de > Wiki > Wiki-Seiten > RequiredFieldsSet()  

RequiredFieldsSet()

 RSS-Feed

/// <summary>
///
checks all fields if they are required, and if so, check if the item has a value for the field
/// </summary>
///
<param name="item"></param>
///
<returns></returns>
public static bool RequiredFieldsSet(this SPListItem item)
{
    foreach (SPField field in item.Fields)
    {
        if (field.Required == false) continue;
        if (field.GetValidatedString(item[field.Id]).IsNullOrEmpty())
        {
            // field has no value
            return true;
        }
    }
    return true;
}

Usage:

SPListItem item = list.Items.Add();
if (item.RequiredFieldsSet())
{
    // it is ok to save the item

}

Zuletzt geändert am 06.01.2009 17:05  von René Hézser