How to use NetSpell???

  •  11-12-2008, 1:08 PM

    How to use NetSpell???

    I'm trying to integrate NetSpell into my app such that when I click the Submit button on the page I spell-check the contents of an ASP.Net TextBox and the CuteEdit XHTML. I've tried poring through the demos, NetSpell docs, etc and I can't find anything comprehensive on how to implement NetSpell beyond the built-in integration with CuteEdit.
     
    Can you provide some guidance? I tried to attach my Default.aspx and the C# code-behind but it won't let me. I have the spellcheck.aspx, spell.cs and spell.css files in my project, the NetSpell DLL and dictionary file in my Bin folder.
     
    When the page posts back it seems to run everything but I always end up in the MisspelledWord event handler. How do I get NetSpell to suggest words? Do I have to handle replacing the actual word in the text?  I need some comprehensive guide to implementing this component in a .Net 2.0 app.
     
    I need to demonstrate this combination of products works or my management won't buy CuteEdit.
     
    Since I can't upload files, here is the source for my page and code-behind:
     

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="BMailV2Edit._Default" %>
    <%@ Register Assembly="CuteEditor" Namespace="CuteEditor" TagPrefix="CE" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
              <asp:TextBox ID="textbox1" runat="server" Text="Put som textt heree" />
            </div>
            <div>
                <ce:editor ID="editor1" runat="server" UseRelativeLinks="false"
                    StyleWithCSS="true" URLType="Absolute"
                    ConfigurationPath="~/CuteSoft_Client/CuteEditor/Configuration/HIG.config"
                    >
                    <FrameStyle BackColor="White" BorderColor="#DDDDDD" BorderWidth="1px" BorderStyle="Solid" Height="100%" Width="100%"></FrameStyle>
                </ce:editor>
                <br /> 
            </div>
                <div>
                <asp:Button ID="Submit1" runat="server" Text="Show Page"
                    onclick="Submit1_Click" />
            </div>
            <div>
                <br />
                <br />
                <asp:Literal id="Output" runat="server"></asp:Literal>
            </div>
        </form>
    </body>
    </html>
     

    using System;
    using System.IO;
    using NetSpell.SpellChecker.Dictionary;

    namespace BMailV2Edit
    {
        public partial class _Default : System.Web.UI.Page
        {

            // instantiate spellchecker
            NetSpell.SpellChecker.Spelling SpellChecker = new NetSpell.SpellChecker.Spelling();
            NetSpell.SpellChecker.Dictionary.WordDictionary WordDictionary = new NetSpell.SpellChecker.Dictionary.WordDictionary();

            protected void Page_Load(object sender, EventArgs e)
            {
                editor1.Setting["security:ImageGalleryPath"] = "~/Graphics";
                editor1.Setting["security:TemplateGalleryPath"] = "~/Templates";

                // get dictionary from cache
                // if not in cache, create new
                WordDictionary = new NetSpell.SpellChecker.Dictionary.WordDictionary();
                WordDictionary.EnableUserFile = false;
                string folderName;

                if (Request.ServerVariables["SERVER_NAME"].ToString() == "localhost")
                {
                    folderName = "bin\\";
                }
                else
                {
                    folderName = "e:\\web\\cuteedit\\bin\\";
                }

                folderName = this.MapPath(Path.Combine(Request.ApplicationPath, folderName));
                WordDictionary.DictionaryFolder = folderName;

                //load and initialize the dictionary
                WordDictionary.Initialize();

                SpellChecker.Dictionary = WordDictionary;
                SpellChecker.SuggestionMode =  NetSpell.SpellChecker.Spelling.SuggestionEnum.PhoneticNearMiss;
                // add event handlers

                SpellChecker.MisspelledWord +=
                    new NetSpell.SpellChecker.Spelling.MisspelledWordEventHandler(SpellChecker_MisspelledWord);

                SpellChecker.ReplacementWord +=
                    new NetSpell.SpellChecker.Spelling.ReplacedWordEventHandler(SpellChecker_ReplacedWord);

                SpellChecker.EndOfText +=
                    new NetSpell.SpellChecker.Spelling.EndOfTextEventHandler(SpellChecker_EndOfText);

                SpellChecker.DoubledWord +=
                    new NetSpell.SpellChecker.Spelling.DoubledWordEventHandler(SpellChecker_DoubledWord);

            }

            protected void Submit1_Click(object sender, EventArgs e)
            {
                editor1.CleanUpMicrosoftWordHTML();
                editor1.CleanUpHTMLCode();

                // Start Spell Checking
               
                SpellChecker.Text = textbox1.Text;
                Session["spellfield"] = "textbox1";
                SpellChecker.SpellCheck();

                // Start Spell Checking
                SpellChecker.Text = editor1.XHTML;
                Session["spellfield"] = "editor1";
                SpellChecker.SpellCheck();
               
                string XHTML="<HTML><BODY>"+editor1.XHTML+ "</BODY></HTML>";
                Output.Text = "<h3>Output</h3><div class=\"CodeBlock\">" + XHTML + "</div>" +
                    "<h3>HTML</h3><div class=\"CodeBlock\">" + Server.HtmlEncode(XHTML).Replace("\n", "<br>") + "</div>";

            }

            private void SpellChecker_DoubledWord(object sender,
                                          NetSpell.SpellChecker.SpellingEventArgs args)
            {
                // update text
                if (Session["spellfield"].ToString() == "textbox1")
                {
                    textbox1.Text = SpellChecker.Text;
                }
                else
                {
                    editor1.XHTML = this.SpellChecker.Text;
                }
            }

            private void SpellChecker_EndOfText(object sender,
                                                System.EventArgs args)
            {
                // update text
                if (Session["spellfield"].ToString() == "textbox1")
                {
                    textbox1.Text = this.SpellChecker.Text;
                }
                else
                {
                    editor1.XHTML = this.SpellChecker.Text;
                }
            }

            private void SpellChecker_MisspelledWord(object sender,
                                                     NetSpell.SpellChecker.SpellingEventArgs args)
            {

                if (Session["spellfield"].ToString() == "textbox1")
                {
                    int i = args.TextIndex;
                    string j = args.Word;
                    int k = args.WordIndex;
                    textbox1.Text = this.SpellChecker.Text;
                }
                else
                {
                    editor1.XHTML = this.SpellChecker.Text;
                }
            }

            private void SpellChecker_ReplacedWord(object sender,
                                                 NetSpell.SpellChecker.ReplaceWordEventArgs args)
            {
                int i = args.TextIndex;
                string j = args.Word;
                int k = args.WordIndex;
                string l = args.ReplacementWord;
                textbox1.Text = this.SpellChecker.Text;
            }
         }
    }

     
View Complete Thread