This topic has not yet been rated - Rate this topic

SPField.DefaultValue Property

Gets or sets the default value for a field.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
[ClientCallableAttribute]
public virtual string DefaultValue { get; set; }

Property Value

Type: System.String
A string that contains the default value.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
SPFieldLookup Datasheet View Bug

There are some compatibility issues when editing Lookup Columns in Datasheet view after setting the DefaultValue property.

See this article for details and a workaround: http://rrfreeman.blogspot.com/2012/03/sharepoint-lookup-column-defaultvalue.html

Set Default Value

To add a default value of today's date you need to assign "[today]" to this property. Yip. the string "[today"]. In other cases you need to convert a DateTime to string like so:

DateTime defaultValue = DateTime.Today.ToString("u");

Default Value
To add a default value of today's date you need to assign "[today]" to this property. Yip. the string "[today"]. In other cases you need to convert a DateTime to string like so:

DateTime defaultValue = DateTime.Today.ToString("u");