다음을 통해 공유


SPContentType.ValidateName Method

Confirms whether a string is acceptable as the name for a content type.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
Public Shared Sub ValidateName ( _
    name As String _
)
'Usage
Dim name As StringSPContentType.ValidateName(name)
public static void ValidateName(
    string name
)

Parameters

Remarks

You can use this method to validate a name string before assigning it as the value of a content type’s Name property. Note that this method does not verify whether the proposed name is a duplicate. That check is made when you try to add the content type to a collection by using the Add method.

Examples

The following example is taken from a console application. The example attempts to validate an intentionally invalid name. As a result, an exception is thrown, and the application prints the exception message to the console.

' Decide on a name for the new content type.
Dim contentTypeName As String = "R&D"
Try
    SPContentType.ValidateName(contentTypeName)

Catch ex As SPException

    Console.WriteLine(ex.Message)

End Try
// Decide on a name for the new content type.
string contentTypeName = "R&D";
try
{
    SPContentType.ValidateName(contentTypeName);

}
catch (SPException ex)
{
    Console.WriteLine(ex.Message);
}

The example code prints the following output to the console.

The content type name cannot contain: \  / : * ? " # % < > { } | ~ &, two consecutive periods (..), or special characters such as a tab.

See Also

Reference

SPContentType Class

SPContentType Members

Microsoft.SharePoint Namespace

Other Resources

Introduction to Content Types

Site and List Content Types

Base Content Type Hierarchy