Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
ValidateName Method

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

public static void ValidateName(
	string name
)

Parameters

name
Type: System.String

A name to validate.

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.

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.
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.
Show:
© 2015 Microsoft