User ID:
Password:
Remember Me:
Forgot Password?
Not a member?
Click here for more information and to register.

    Modifying Spell Check for SharePoint Server 2007



    Finally, the call to the WebService is executed and the results come back in the form of a "WebResponse" object that is converted to a "StreamReader" that needs to be interpreted; the final result is a XML string, "ResponseSoap". The response of the example is in the form:

    <?xml version="1.0" encoding="utf-8" ?>
       - <soap:Envelope xmlns:soap= "http://schemas.xmlsoap.org/soap/
                                               envelope/"
                        xmlns:xsi="http://www.w3.org/2001/
                                          XMLSchema-instance"
                        xmlns:xsd="http://www.w3.org/2001/XMLSchema">
          - <soap:Body>
             - <SpellCheckResponse
                  xmlns="http://schemas.microsoft.com/sharepoint/
                                publishing/spelling/">
                - <SpellCheckResult>
                  <errorCode>Ok</errorCode>
                  <detectedLanguage>1033</detectedLanguage>
                   - <spellingErrors>
                      - <SpellingErrors>
                        <chunkIndex>0</chunkIndex>
                         - <flaggedWords>
                            - <FlaggedWord>
                              <word>rou</word>
                              <type>UnknownWord</type>
                              <offset>3</offset>
                              </FlaggedWord>
                              </flaggedWords>
                              </SpellingErrors>
                              </spellingErrors>
                               - <spellingSuggestions>
                                  - <SpellingSuggestions>
                                    <word>rou</word>
                                     - <sug>
                                       <string>roue</string>
                                       <string>rout</string>
                                       <string>roux</string>
                                       <string>roe</string>
                                       <string>row</string>
                                       <string>rob</string>
                                       </sug>
                                       </SpellingSuggestions>
                                       </spellingSuggestions>
                                    </SpellCheckResult>
                                 </SpellCheckResponse>
          </soap:Body>
       </soap:Envelope>
    

    In the SOAP response, note that the corrector—in the first string (chunkIndex=0)—has identified an unknown word (FlaggedWord-word=rou), that probably has an error in the third character (offset=3). The suggestions section indicates that the unidentified word has six possible corrections in the dictionary. The second string is not found in the response, signifying it is accepted by the corrector.

    The remaining code implementation is elemental and can be used in each SharePoint component (WebParts, WebControls, Web pages, and so forth). The last task is to extract the relevant information from the XML response and present it to the user in the desired way.

    Spell Check Default Components

    It is not necessary to use WebService spell check directly, as indicated in the last section; it is also possible to use the existing SharePoint default infrastructure for this purpose. The default implementation of spell check for MOSS is based in one ASPX page and two JavaScript files:

    • SpellChecker.aspx: (C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\SpellChecker.aspx) contains the Web page used to show words with errors and the suggestions (shown in Figure 1)
    • SpellChecker.js: (C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\3082\SpellChecker.js) contains the routines to call the WebService, show and rectify words with errors
    • SpellCheckerEntirePage.js: (C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\3082\SpellChecker.js) works as a link between the aspx page and the routines of the JavaScript in SpellChecker.js.

    In the event the Language cannot be detected, the ASPX page initially shows a menu to select it from the available Languages List.

    The default MOSS corrector page can be initiated from each ASPX page as well. To view the process, create a new file with the .aspx extension ("spellcheck.aspx", for example) in the directory "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\". Open the file with any ASCII text editor (Notepad) and add a reference to the SharePoint assembly:

    <%@ Register Tagprefix="SharePoint"
    Namespace="Microsoft.SharePoint.WebControls"
    Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral,
    PublicKeyToken=71e9bce111e9429c" %>
    

    Then, create references to the files with the JavaScripts:

    <SharePoint:ScriptLink language="javascript"
                           name="core.js" runat="server" />
    <SharePoint:ScriptLink language="javascript"
                           name="SpellCheckEntirePage.js"
                           runat="server" />
    

    And a JavaScript section to call Spell Check:

    <script language="javascript" type="text/javascript">
       function CheckSpell()
       {
          SpellCheckEntirePage('/_vti_bin/SpellCheck.asmx',
                               '/_layouts/SpellChecker.aspx');
       }
    </script>
    

    Finally, create the content controls where the user can write a text to be checked. In the example, it is one text box, but as many as are required can be created and spell check will loop through all of them scanning for errors. Use the syntax:

    Some text to check &nbsp;&nbsp;
    <input type="text" name="SomeText">
    <br><br>
    

    The button at the end will call the JavaScript and spell check:

    <a href="javascript:" onclick="CheckSpell();">Spell Checker</a>

    Call the aspx from MOSS using the URL (http[s]://ServerName/_layouts/ spellcheck.asp). After clicking the button, a popup window will appear, showing the incorrect words and the correction suggestions:


    (Full Size Image)

    Figure 2: ASPX custom page using default spell check

    With the preceding code, all the texts found on the page will be scanned. If you want to exclude any of the text from correction, use the attribute "excludeFromSpellCheck" in the HTML syntax. For example, to create a text box controlled by the server where no spell check is desired, use:

    <asp:TextBox ID="TextBoxNoControled" runat="server"
                 excludeFromSpellCheck="true" />
    
    Note: The "excludeFromSpellCheck" attribute can be used in a similar way in client-side controls by using HTML code.

    If necessary, it also is possible to modify the files SpellChecker.aspx, SpellChecker.js and/or SpellCheckerEntirePage.js, but it is not recommended or effective because any future Microsoft Service Pack can revert the files to the original state.

    Dictionary Modifications

    MOSS has default correction dictionaries for each supported language, but it is impossible to modify them. However, it is possible to add words in such a way that they are not identified as errors. The following process creates a type of custom dictionary for these words:

    1. Create a new Document Library, "Spelling," at the root of the Portal.
    2. Create a text file, "Custom Dictionary.txt," locally.
    3. Add all the words that should not be recognized as spelling errors in the text file, one word per line.
    4. Upload the text file to the newly created Library above.

    Only one "Custom Dictionary" Document Library is possible for each site collection; the names of the Library and text file need to be exactly as indicated and the Library must be located at the root of the Portal.

    Conclusion

    A valuable feature of SharePoint 2007 is the introduction of an online spell check program. The system is presented as a WebService, but the feature has some errors that need workarounds to function properly.

    Spell Check is a default component of Microsoft Office SharePoint Server (MOSS) but is not available in Windows SharePoint Services (WSS). The system is a welcome adaption and covers the supported SharePoint Languages. It is effective for detecting orthography errors and provides correction suggestions; however, the downside is that it lacks a grammar and a thesaurus and the dictionaries cannot be modified.

    The default window of the corrector can be used in custom components inside SharePoint, as ASPX pages, with the inclusion of a few lines of code. Finally, although the dictionaries cannot be modified, it is possible resolve this inadequacy by creating a list of words to be excluded from Spell Check control.

    About the Author

    Gustavo Velez is a MCSD Senior Application Developer for Winvision (http://www.winvision.nl), a Microsoft Gold Partner in the Netherlands. He has many years experience developing Windows and Office applications, and more than six years of daily programming experience with SharePoint. The author's articles can be found in many of the leading trade magazines in English, Dutch, and Spanish. He is also pleased to be Webmaster of http://www.gavd.net/servers, the only Spanish-language site dedicated to SharePoint. Spanish-language readers may want to consult Velez's book; Programacisn con SharePoint 2007 (http://www.dotnetmania.com/Libros/index.html). Velez has been awarded MVP status (Most Valuable Professional, http://mvp.support.microsoft.com/), in the area of SharePoint MOSS.


    IT Offers


    Top Authors