Export (0) Print
Expand All

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)

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:
© 2014 Microsoft