Wednesday, June 2, 2010

SPField - Specifying default date time

//Check if the column is already there
//Add PostedDate field
SPFieldDateTime customDateTimeField;
try
{
    customDateTimeField = (SPFieldDateTime)list.Fields["PostedDate"];
}
catch (Exception ex)
{
    customDateTimeField = (SPFieldDateTime)web.Fields.CreateNewField(SPFieldType.DateTime.ToString(), "PostedDate");
    customDateTimeField.DisplayFormat = SPDateTimeFieldFormatType.DateTime;
    customDateTimeField.Required = false;
    customDateTimeField.DefaultValue = "[today]";
    list.Fields.Add(customDateTimeField);
    list.Update();
}

Technorati Tags: ,,,

No comments:

Post a Comment