Return to doc.sitecore.com

Valid for Sitecore 5.2, 5.3
What is the difference between AssertItemName, IsItemNameValid, and GetItemNameError?

Q:

The Sitecore.Data.Items.ItemUtil class includes three very similar methods.  What is the difference between AssertItemName, IsItemNameValid, and GetItemNameError?

A:

  1. IsItemNameValid returns true if the given name is valid, false otherwise.
  2. GetItemNameError returns a string explaining why the given name is not valid.
  3. AssertItemName throws an exception if the given name is not valid.

    AssertItemNameuses the other methods as follows:

      if (!IsItemNameValid(name)) {
        throw SomeException(GetItemNameError(name));
      }