This is a migrated thread and some comments may be shown as answers.

How to update .tdf for raddictionary automatically

3 Answers 68 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Kjell
Top achievements
Rank 1
Kjell asked on 17 Apr 2012, 04:08 PM
I have several dictionaries stored outside of the XAP file and I load the approriate one manually. I did this in order to minimize the size of the xap.

To load the dictionary, I use the 'WebClient()' class and do the following in OpenReadCompletedEventHandler
System.IO.Stream st = e.Result;
dictionary = new RadDictionary();
dictionary.Load(st);
((DocumentSpellChecker)this.txtDesc.SpellChecker).AddDictionary(dictionary, CultureInfo.CurrentCulture);

The dictionary is loading properly, however adding to the dictionary only works for the session, which makes sense. So my question is, how do I sync the .tdf file when the user selects "Add to dictionary". I am able to capture the "DataChanged" event, so I guess in that event handler I just need to pass the dictionary ( or even better just the word) to my webservice and overwrite the existing .tdf. How do I do that?

Also I realize this means all users will be editing the same .tdf, and that is not ideal, but right now it doesn't work at all and I just want to get it working. I am still on the latest SL4 build.

3 Answers, 1 is accepted

Sort by
0
Andrew
Telerik team
answered on 18 Apr 2012, 11:07 AM
Hello Kjell,

DocumentSpelChecker uses custom dictionaries when you click the add or remove buttons. These custom dictionaries use isolated storage by default. You can alter the logic of those buttons the way you described, but we would recommend implementing the IWordDictionary interface instead. We have a class named RadIsolatedStorageCustomDictionary. You can download the source code for our controls and locate the file. You can alter the logic we have implemented to write to a file on the server instead in the IsolatedStorage and then using this class would cause everyone to use the same common dictionary every time they start the application.
Please consider that approach and get back to us if you need additional assistance. 

Greetings,
Andrew
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Kjell
Top achievements
Rank 1
answered on 27 Apr 2012, 10:41 PM
I'm ok with using isolated storage but I'm not sure how to retrieve the data when the next session is started.  I assume that only words the user adds are stored there, so how do I pull them up next time and merge them in with the default dictionary?
0
Andrew
Telerik team
answered on 02 May 2012, 04:17 PM
Hi Kjell,

First you need a way to access the IsolatedStorage like so:

IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication();
Now, you can use a text file to store all the words the users have added. You can check if such file is available and if so read the words from it when the your application starts.
if (isolatedStorageFile.FileExists(customDictionaryName))
            {
                using (IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(customDictionaryName, FileMode.Open, isolatedStorageFile))
                {
                    using (StreamReader reader = new StreamReader(fileStream))
                    {
                        string word;
                        while ((word = reader.ReadLine()) != null)
                        {
                            if (word != string.Empty)
                            {
                                 //do something with the retrieved word
                            }
                        }
                    }
                }
            }
customDictionaryName is the name of the file you will store your words in.
You will have to update the file too when you want to add some words to it. You can do so as follows:
using (IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(customDictionaryName, FileMode.Create, isolatedStorageFile))
            {
                using (StreamWriter writer = new StreamWriter(fileStream))
                {
                    foreach (string word in words)
                    {
                        writer.WriteLine(word);
                    }
                }
            }
The variable words is the collection you use for storing the words runtime.
Here you can read more about IsolateStorage and how you can use it in more complex scenarios.


Regards,
Andrew
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
RichTextBox
Asked by
Kjell
Top achievements
Rank 1
Answers by
Andrew
Telerik team
Kjell
Top achievements
Rank 1
Share this question
or