MetadataDefaults.SetFieldDefault Method (String, String, String)
Sets a default value for a default field to apply to documents at a specified location.
Namespace: Microsoft.Office.DocumentManagement
Assembly: Microsoft.Office.DocumentManagement (in Microsoft.Office.DocumentManagement.dll)
Syntax
'Declaration
Public Function SetFieldDefault ( _
folderPath As String, _
fieldName As String, _
value As String _
) As Boolean
'Usage
Dim instance As MetadataDefaults
Dim folderPath As String
Dim fieldName As String
Dim value As String
Dim returnValue As Boolean
returnValue = instance.SetFieldDefault(folderPath, _
fieldName, value)
public bool SetFieldDefault(
string folderPath,
string fieldName,
string value
)
Parameters
folderPath
Type: System.StringServer-relative path that links to the location at which to set the default
fieldName
Type: System.StringInternal name of the SPField object at which to set the default
value
Type: System.StringThe default value
Return Value
Type: System.Boolean
true if successful; otherwise, false
Exceptions
Exception | Condition |
---|---|
ArgumentNullException | The folderPath parameter is set to a null reference (Nothing in Visual Basic) or set to String.Empty. The folderPath parameter should be a server-relative URL that links to a SPFolder object in the document library. (ArgumentNullException.ParamName="folderPath") |
ArgumentNullException | The fieldName parameter is set to null 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
The value should be appropriate for the type of field the default is being set on. For example, use a DateTime string for a SPFieldDateTime.
Examples
SPSite site = new SPSite("http://contoso"); SPWeb web = new site.OpenWeb("/"); MetadataDefaults defaults = MetadataDefaults("/Documents", web); defaults.SetFieldDefault("/Documents/AdventureWorks", "Title", "AdventureWorks Document"); defaults.Update();