Edit this page

Spellcheck

The RadRichTextEditor control is designed to support "spell checking as you type" by setting a single property and specifying a proper dictionary to it. This topic will explain you the following:

Enabling SpellCheck

To enable or disable the spell checking functionality (present as red wavy underlines below unrecognized words), you can use the IsSpellCheckingEnabled property on RadRichTextEditor. When the property is false, no dictionaries are loaded and no overhead is incurred for spell checking.

Figure 1: Spell checking as you type

richtexteditor-features-spellcheck 001

You can customize the spell checker by using the SpellChecker property of RadRichTextEditor. It’s of type ISpellChecker. By default, an object of type DocumentSpellChecker that implements the interface, is used for this property. You can either use it or provide your custom class that implements the ISpellChecker interface.

When you right click a misspelled word, the context menu gives you the opportunity to open a SpellCheckingDialog. Thus, the user can correct the word, add it to the dictionary or ignore it.

note

Since R2 2017 SP the SpellCheckingDialog allows the user to enter some custom text by using a RadTextBox if no appropriate word exist in the offered list.

Figure 2: Spell checking dialog

richtexteditor-features-spellcheck 002

note

RadRichTextEditor can also be configured to be used with a spell-checker using an OpenOffice dictionary and the NHunspell library: RadRichTextEditor OpenOffice Spell Checking.

Dictionaries

The dictionaries in RadRichTextEditor implement the IWordDictionary interface. Easy interoperability with dictionaries from RadSpell for ASP.NET is achieved through the RadDictionary class, which supports the loading of a dictionary directly from the *.tdf files, used with RadSpell. You can find TDF dictionaries for some languages here.

Here is an example of a RadDictionary loaded from a TDF file.

note

When adding a RadDictionary or similar object use the AddDictionary(IWordDictionary dictionary, CultureInfo culture) method of the DocumentSpellChecker . You can also associate a dictionary with a specific culture. The method to remove this dictionary is RemoveDictionary(CultureInfo culture) .

note

The given example doesn't contain the logic used to read the TDF file as a Stream .

private void LoadDictionary(Stream tdfFileStream)
{
    RadDictionary dictionary = new RadDictionary();
    dictionary.Load(tdfFileStream);
    ((DocumentSpellChecker)this.radRichTextEditor1.SpellChecker).AddDictionary(dictionary, CultureInfo.InvariantCulture);
}

Private Sub LoadDictionary(ByVal tdfFileStream As Stream)
    Dim dictionary As New RadDictionary()
    dictionary.Load(tdfFileStream)
    CType(Me.radRichTextEditor1.SpellChecker, DocumentSpellChecker).AddDictionary(dictionary, CultureInfo.InvariantCulture)
End Sub

RadWordsDictionary

RadWordsDictionary implements the IWordDictionary interface and is capable of reading words from text files that contain one word per line. An example of such files are the .dic dictionaries.

Load stream in RadWordsDictionary

private void LoadWordDictionaryStream(Stream dictStrem)
{
    Telerik.WinControls.SpellChecker.Proofing.RadWordsDictionary dictionary = new Telerik.WinControls.SpellChecker.Proofing.RadWordsDictionary();
    dictionary.Load(dictStrem);
}

Private Sub LoadWordDictionaryStream(dictStrem As Stream)
    Dim dictionary As New Telerik.WinControls.SpellChecker.Proofing.RadWordsDictionary()
    dictionary.Load(dictStrem)
End Sub

One of the constructor overloads of the RadWordsDictionary class enables you to pass a parameter of type IEnumerable<string>, which can help you create your own dictionary with a custom set of words.

Create RadWordsDictionary from strings

private void LoadWordDictionaryStream()
{
    List<string> words = new List<string>();
    words.Add("Test");
    words.Add("Teacher");
    words.Add("Sister");
    Telerik.WinControls.SpellChecker.Proofing.RadWordsDictionary dictionary = new Telerik.WinControls.SpellChecker.Proofing.RadWordsDictionary();
    dictionary.Load(words);
}

Private Sub LoadWordDictionaryStream()
    Dim words As New List(Of String)()
    words.Add("Test")
    words.Add("Teacher")
    words.Add("Sister")
    Dim dictionary As New Telerik.WinControls.SpellChecker.Proofing.RadWordsDictionary()
    dictionary.Load(words)
End Sub

Custom Dictionaries

One feature of the SpellChecker in RadRichTextEditor is to add a word to a user-defined custom dictionary to enable domain-specific applications. Such dictionary should implement the IWordCustomDictionary interface. For that purpose the RadRichTextEditor provides you with the RadIsolatedStorageCustomDictionary class out of the box. It allows you to persist the word list in a file located in the Isolated Storage.

Here is an example of a such dictionary which adds the words in the "CustomDictionary.txt" marked as a Site-scoped IsolatedSotrageFile.

tip

The IsolatedStorageScope enumeration has the following values:

  • Site - the dictionary defined in this scope is available for each application hosted on the same site.
  • Application - the dictionary is available only for the particular application.>
note

When adding a dictionary that implements the ICustomWordDictionary interface object use AddCustomDictionary(ICustomWordDictionary customDictionary, CultureInfo culture) method for the DocumentSpellChecker class. You can also associate a custom dictionary to a specific culture. The method to remove it is RemoveCustomDictionary(ICustomWordDictionary customDictionary, CultureInfo culture) .

private void CreateCustomDictionary()
{
    RadIsolatedStorageCustomDictionary dictionary = new RadIsolatedStorageCustomDictionary(IsolatedStorageScope.Site, "CustomDictionary.txt");
    DocumentSpellChecker spellchecker = new DocumentSpellChecker(dictionary);
    this.radRichTextEditor1.SpellChecker = spellchecker;
}

Private Sub CreateCustomDictionary()
    Dim dictionary As New RadIsolatedStorageCustomDictionary(IsolatedStorageScope.Site, "CustomDictionary.txt")
    Dim spellchecker As New DocumentSpellChecker(dictionary)
    Me.radRichTextEditor1.SpellChecker = spellchecker
End Sub

If you want to have a temporary custom dictionary, that will only be available for a single application session, you can use the RadNonPersistentCustomDictionary object.

If you want to have a temporary custom dictionary, that will only be available for a single application session, you can use the RadNonPersistentCustomDictionary object.

Adding a Word

To add a word to a dictionary you can either use the AddWord method of the DocumentSpellChecker or of the dictionary itself. Using the first one you can add a word to multiple dictionaries associated to the same culture. This is done by passing the desired culture as parameter to the method.

note

Using the overload of the AddWord method that takes only the word as argument is equal to using the second overload and passing CultureInfo.InvariantCulture as argument.

Using the AddWord method of the dictionary itself will add the word only to the respective dictionary.

Here is an example.

this.radRichTextEditor1.SpellChecker.AddWord("RadRichTextEditor", CultureInfo.InvariantCulture);

Me.radRichTextEditor1.SpellChecker.AddWord("RadRichTextEditor", CultureInfo.InvariantCulture)

Internationalization

The spell checking component is designed to suit scenarios where different cultures take place in the same application. Internationalization is achieved through associating each dictionary and custom dictionary with a specific culture (or the InvariantCulture as the default one).

Here is an example.

note

The given example doesn't contain the logic used to read the TDF file as a Stream .

private void LoadDictionary(Stream tdfFileStream)
{
    RadDictionary dictionary = new RadDictionary();
    dictionary.Load(tdfFileStream);
    ((DocumentSpellChecker)this.radRichTextEditor1.SpellChecker).AddDictionary(dictionary, CultureInfo.InvariantCulture);
}

Private Sub LoadDictionary(ByVal tdfFileStream As Stream)
    Dim dictionary As New RadDictionary()
    dictionary.Load(tdfFileStream)
    CType(Me.radRichTextEditor1.SpellChecker, DocumentSpellChecker).AddDictionary(dictionary, CultureInfo.InvariantCulture)
End Sub