Search code examples
c#.netvisual-studiohunspellnhunspell

How to install Hunspell for C# application?


I want to implement spell check and dictionary in my C# windows-based application. From Google, I found that hunspell is one of the best options to implement this functionality. I have installed nhunspell using visual studio NuGet as per the suggestion from the below URL. But when I try to execute the code, getting error "AFF File not found: C:\TestProject\TestHunshell\bin\Debug\en_us.aff"

When I search the installed hunspell package .aff & .dic files are not found. I am not sure from where I can download and install or paste "en_us.aff", "en_us.dic" files to my solution.

Can someone please suggest the proper way to install and implement hunspell in the C# windows application?

Code Project Reference URL

Error


Solution

  • Based on my test, you could download aff & .dic files from the following link:

    en_US.aff

    en_US.dic

    After clicking on the click, we should right-click to save as a txt file.

    Then, we need to move the .txt to change it to the extension .aff or .dic.

    Finally, we move the two files to the project\bin\debug folder.

    Here is my test code and result:

        Hunspell hunspell = new Hunspell("en_US.aff", "en_US.dic");
        Console.WriteLine("Hunspell - Spell Checking Functions");
        Console.WriteLine("¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯");
    
        Console.WriteLine("Check if the word 'Recommendation' is spelled correct");
        bool correct = hunspell.Spell("Recommendation");
        Console.WriteLine("Recommendation is spelled " +
           (correct ? "correct" : "not correct"));
    
        Console.WriteLine("");
        Console.WriteLine("Make suggestions for the word 'Recommendatio'");
        List<string> suggestions = hunspell.Suggest("Recommendatio");
        Console.WriteLine("There are " +
           suggestions.Count.ToString() + " suggestions");
        foreach (string suggestion in suggestions)
        {
            Console.WriteLine("Suggestion is: " + suggestion);
        }
    

    Result:

    enter image description here