Voici ce que j'utilise dans mon programme C# MVC3
private const string AFF_FILE = "~/App_Data/en_us.aff";
private const string DICT_FILE = "~/App_Data/en_us.dic";
public ActionResult Index(string text)
{
using(NHunspell.Hunspell hunspell = new NHunspell.Hunspell(Server.MapPath(AFF_FILE), Server.MapPath(DICT_FILE)))
{
Dictionary<string, List<string>> incorrect = new Dictionary<string, List<string>>();
text = HttpUtility.UrlDecode(text);
string[] words = text.Split(new char[] { ' ' }, StringSplitOption.RemoveEmptyEntries);
foreach ( string word in words)
{
if (!hunspell.Spell(word) && !incorrect.ContainsKey(word))
{
incorrect.Add(word, hunspell.Suggest(word));
}
}
return Json(Incorrect);
}
}
public ActionResult Suggest(string word)
{
using(NHunspell.Hunspell hunspell = new NHunspell.Hunspell(Server.MapPath(AFF_FILE), Server.MapPath(DICT_FILE)))
{
word = HttpUtility.UrlDecode(word);
return Json(hunspell.Suggest(word));
}
}