MetadataDefaults.SetFieldDefault method (SPFolder, String, String)

Sets a default for a field at a location.

Namespace:  Microsoft.Office.DocumentManagement
Assembly:  Microsoft.Office.DocumentManagement (in Microsoft.Office.DocumentManagement.dll)

Syntax

'Declaration
Public Function SetFieldDefault ( _
    folder As SPFolder, _
    fieldName As String, _
    value As String _
) As Boolean
'Usage
Dim instance As MetadataDefaults
Dim folder As SPFolder
Dim fieldName As String
Dim value As String
Dim returnValue As Boolean

returnValue = instance.SetFieldDefault(folder, _
    fieldName, value)
public bool SetFieldDefault(
    SPFolder folder,
    string fieldName,
    string value
)

Parameters

Return value

Type: System.Boolean
true if successful; otherwise, false

Exceptions

Exception Condition
ArgumentNullException

The folder parameter is set to a null reference (Nothing in Visual Basic). The folder parameter should be a non-null SPFolder object that represents a folder in the document library. (ArgumentNullException.ParamName="folder")

ArgumentNullException

The fieldName parameter is set to a null reference (Nothing in Visual Basic) or set to String.Empty. The fieldName parameter should be an internal name of a field on the document library. (ArgumentNullException.ParamName="fieldName")

ArgumentNullException

The value parameter is set to a null reference (Nothing in Visual Basic) or set to String.Empty. The value parameter should be the default value that is applied to the specified SPField object on documents added to this folder. (ArgumentNullException.ParamName="value")

Remarks

This method sets a default value on a field to apply to documents added to the specified location. The value should be appropriate for the type of field the default is being set on. For example, a DateTime string for a SPFieldDataTime object.

Examples

SPSite site = new SPSite("http://contoso"); SPWeb web = new site.OpenWeb("/"); MetadataDefaults defaults = MetadataDefaults("/Documents", web); SPFolder folder = web.GetFolder("/Documents/AdventureWorks"); defaults.SetFieldDefault(folder, "Title", "AdventureWorks Document"); defaults.Update();

See also

Reference

MetadataDefaults class

MetadataDefaults members

SetFieldDefault overload

Microsoft.Office.DocumentManagement namespace

MetadataDefaults