Partager via


CreateProperty Method

Creates a property of the specified data type in the catalog system and returns a CatalogProperty object containing information about the property.

Namespace:  Microsoft.CommerceServer.Catalog
Assembly:  Microsoft.CommerceServer.Catalog (in Microsoft.CommerceServer.Catalog.dll)

Syntax

'Declaration
Public Function CreateProperty ( _
    propertyName As String, _
    dataType As CatalogDataType, _
    maxLength As Integer _
) As CatalogProperty
'Usage
Dim instance As CatalogContext
Dim propertyName As String
Dim dataType As CatalogDataType
Dim maxLength As Integer
Dim returnValue As CatalogProperty

returnValue = instance.CreateProperty(propertyName, _
    dataType, maxLength)
public CatalogProperty CreateProperty(
    string propertyName,
    CatalogDataType dataType,
    int maxLength
)
public:
CatalogProperty^ CreateProperty(
    String^ propertyName, 
    CatalogDataType dataType, 
    int maxLength
)
public function CreateProperty(
    propertyName : String, 
    dataType : CatalogDataType, 
    maxLength : int
) : CatalogProperty

Parameters

  • propertyName
    Type: System..::.String
    The name of the property to create. Should not be nullNothingnullptra null reference (Nothing in Visual Basic).
  • maxLength
    Type: System..::.Int32
    The maximum length for this dataType. This value is not valid for any other dataType.

Return Value

Type: Microsoft.CommerceServer.Catalog..::.CatalogProperty
A CatalogProperty object containing the newly created catalog property.

Exceptions

Exception Condition
ArgumentNullException

The propertyName is nullNothingnullptra null reference (Nothing in Visual Basic).

ValidationException

The propertyName is invalid.

NotAuthorizedException

The caller is not authorized to perform this operation.

EntityAlreadyExistsException

The propertyName already exists in the catalog system.

Remarks

This method creates a property in the catalog system and returns a CatalogProperty object. You can use the CatalogProperty object to set various attributes on the property and add enumeration values to the property if the data type of the property is Enumeration. You should call the Save method to save the changes made to the CatalogProperty object to the catalog system. You do not need to call the Save method if you create the property but do not change its attributes. The catalog system supports the following data types:

The propertyName should:

  • Not be nullNothingnullptra null reference (Nothing in Visual Basic) or blank.

  • Not exceed 100 characters.

  • Not contain the .,"[] characters.

  • Not begin with a digit.

If the dataType is String then the maxLength should be between 1 and 4000. A property of Enumeration data type will be created with a maximum length of 128 characters and a property of FilePath data type will be created with a maximum length of 256 characters. For all other data types the maxLength will be ignored.

Examples

This example shows how to create a multilingual string property and set its DisplayName and IsFreeTextSearchable attributes.

private void CreateMultilingualProperty(CatalogContext catalogContext)
{
  CatalogProperty catalogProperty = catalogContext.CreateProperty("StringProperty", CatalogDataType.String, 100);
  catalogProperty.Information.CatalogProperties[0].LanguageSensitive = true;
  catalogProperty.Information.CatalogProperties[0].DisplayName = "Property Displayname";
  catalogProperty.Information.CatalogProperties[0].IsFreeTextSearchable = true;
  catalogProperty.Save();
}

Permissions

See Also

Reference

CatalogContext Class

CatalogContext Members

Microsoft.CommerceServer.Catalog Namespace