Back to Devexpress

How to: Add Dictionaries from an Assembly Resource

windowsforms-400665-controls-and-libraries-spell-checker-examples-how-to-add-dictionaries-from-an-assembly-resource.md

latest2.6 KB
Original Source

How to: Add Dictionaries from an Assembly Resource

  • Nov 28, 2023

The code sample below shows how to use the GetExecutingAssembly() and GetManifestResourceInfo(String) methods to deploy dictionaries in the application’s assembly.

The LoadFromStream(Stream, Stream, Stream) method allows you to load dictionary files from a stream.

When you load dictionaries from assembly resources, make sure that the dictionary files’ Build Action property is set to Embedded Resource.

csharp
private void Form1_Load(object sender, EventArgs e)
{
    //Create a new dictionary instance
    SpellCheckerISpellDictionary dictionary = new SpellCheckerISpellDictionary();

    //Create stream objects for each dictionary file
    Stream affStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("WindowsApplication27.Dictionaries.english.aff");
    Stream dicStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("WindowsApplication27.Dictionaries.american.xlg");
    Stream alphStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("WindowsApplication27.Dictionaries.EnglishAlphabet.txt");

    //Load files to the dictionary
    dictionary.LoadFromStream(dicStream, affStream, alphStream);

    //Add dictionary to the spell checker collection
    spellChecker1.Dictionaries.Add(dictionary);
}
vb
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
    ' Create a new dictionary instance
    Dim dictionary As New SpellCheckerISpellDictionary()

    ' Create stream objects for each dictionary file
    Dim affStream As Stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("english.aff")
    Dim dicStream As Stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("american.xlg")
    Dim alphStream As Stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("EnglishAlphabet.txt")

    ' Load files to the dictionary
    dictionary.LoadFromStream(dicStream, affStream, alphStream)

    'Add dictionary to the spell checker collection
    spellChecker1.Dictionaries.Add(dictionary)
End Sub